Reputation: 177
I created a upload and download file in Blazor Server, all are working on uploads, which we restrict it on doc, .docx, .pdf, .xls, .xlsx, .ptt, .pttx, and .vsdx, all files are good on when uploading it on the local folder/local server folder, but when downloading the file, all of them are working fine, except for one, which is the .vsdx, which results to "This localhost page can’t be found" and when you try to right click and save as, it show "failed". I tried to open the uploaded .vsdx file on my local and in our server, it opens without any error, we tried different .vsdx files and all of them are having the same error.
I'm using this code to download the uploded files to the users.
string appurl = NavMan.BaseUri;
FilePath = appurl + "Storage/" + AppFiles.FileName;
and here's on the razor page
<a href="@FilePath" target="_blank">here</a>
Is there a way to make the .vsdx file working on downloads? and why does the .vsdx only encounter the error? is there a restriction or special approach for it to make it work?
thank you everyone, I appreciate all your responses.
Upvotes: 0
Views: 420
Reputation: 177
Good Day everyone
Thank you for all your response, based on your comments, I fix the issue by create a web api on the app inside the blazor app, and call it, here's my code.
[HttpGet]
[Route("[action]/{TranID}/{id}")]
public async Task<IActionResult> DownloadFile(int TranID,int Id)
{
var GetFile = await myServices.GetAttachment(Id);
var GetFilePath = GetFile.FilePath + "\\" + GetFile.FileName;
var memory = new MemoryStream();
using(var stream = new FileStream(GetFilePath, FileMode.Open))
{
await stream.CopyToAsync(memory);
}
memory.Position = 0;
return File(memory, GetFile.ContentType, GetFile.FileName);
}
Upvotes: 0