I need pipeline the PDF or excel file from azure blob storage to front end using an API. i am using download to byte array of blob storage and then convert that to memory stream to send it back to a users.
this is my controller
[AllowAnonymous]
[HttpGet]
[Route("GetFiles")]
public HttpResponseMessage GetFiles()
{
const string StorageAccountName = "nameofAccount";
const string StorageAccountKey = "TheKey";
try
{
var storageAccount = new CloudStorageAccount(new StorageCredentials(StorageAccountName, StorageAccountKey), true);// login to azure and storage Account
var bloblClinet = storageAccount.CreateCloudBlobClient();// get blob client refernce
var container = bloblClinet.GetContainerReference("crmtestblob");// get container refernce
var blob = container.GetBlockBlobReference("test.xlsx");
long fileByteLength = blob.Properties.Length;// this return -1
byte[] fileContent = new byte[100000];
var MyArray = blob.DownloadToByteArray(fileContent, 0);
HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
var stream = new MemoryStream(MyArray);//application/octet-stream
result.Content = new StreamContent(stream);//application/vnd.ms-excel
result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
{
FileName = "test.xlsx"
};
return result;
}
catch (Exception ex)
{
return new HttpResponseMessage(HttpStatusCode.InternalServerError);
}
}
i get response 200 but no file is sent, or the file is corrupted any help would be great