i am working on a website where you could upload a image onto azure storage as a blob and also to download the blob, however when i download the image it gives me a "this file format cannot be opened" when opening the pic. i was wondering where could i display the fileStream?
heres my javascript:
@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<div class="container">
@Html.ActionLink("Upload to Azure Blob", "UploadBlob", new { Controller = "blob" }, new { @class = "btn btn-link" })
<div class=" table table-striped table-responsive">
<table id=" tablex">
<thead>
<tr>
<th>Container</th>
<th>Actual FileName</th>
<th> Uri </th>
</tr>
</thead>
<tbody>
@if(Model != null)
{
foreach (var item in Model)
{
<tr id="row_@item.PrimaryUri">
<td>@item.BlockContainerName</td>
<td>@item.ActualFileName</td>
<td>
<a herf=@item.PrimaryUri>@item.PrimaryUri </a>
</td>
@*<td>@Html.ActionLink("Remove", "DeletedBlob", new { controller = "blob", file = @item.FileNameWithoutExt, extension = @item.FileNameWithoutExt })</td> *@
<td><a href='@Url.Action("Download", "DownloadBlob", new { file = @item.FileNameWithoutExt, extension = @item.FileNameWithoutExt })'>Download</a></td>
<td>
<input type="submit" href="#" class="btn btn-link" id="btndel" value="Remove" data-id="@item.ActualFileName" />
</td>
</tr>
}
}
</tbody>
</table>
</div>
</div>
This is the javascript method ive written in order to download the blob however i've been trying to find out where the problem
In my controller class i have:
public async Task<ActionResult> DownloadBlob(string file, string extension)
{
string downloadPath = await repo.DownloadBlobAsync(file, extension);
return Json(downloadPath);
}
and in my storage class:
public async Task<string> DownloadBlobAsync (string file, string fileExtension)
{
_cloudBlobContainerx = _cloudBlobClientx.GetContainerReference(containerNamex);
CloudBlockBlob blockBlob = _cloudBlobContainerx.GetBlockBlobReference(file + "." + fileExtension);
var path = downloadPath + file + "." + fileExtension;
using (var fileStream = System.IO.File.OpenWrite(path))
{
//fileStream.Position = 1;
//fileStream.Seek(0, SeekOrigin.Begin);
await blockBlob.DownloadToStreamAsync(fileStream);
return path;
}
}