I'm becoming crazy to get physical file from database field. I use asp.net MVC project (dotnet core 1.1). Thanks in avance and happy Christams!
In some part of my CONTROLLER :
public void Download(int id)
{
downloadMyFile(_context.myTable.Find(id).MyBLOBField,
_context.myTable.Find(id).MyFieldContentType,
_context.Richieste.Find(id).MyFieldOriginalFileName
);
}
public FileContentResult downloadMyFile(byte[] fileBytes,
string fileContent, string fileName)
{
return File(fileBytes, fileContent, fileName);
}
My VIEW :
<a asp-action="Download" asp-route-id="@Model.Id"> Download File</a>
**
My notes:
If I use this, works:
public FileResult download()
{
var fileName = @"myRealFileNameStoredInTheServer.ext";
var filepath = $"Downloads/{fileName}";
byte[] fileBytes = System.IO.File.ReadAllBytes(filepath);
return File(fileBytes, "application/x-msdownload", fileName);
}
BUT WHEN PASS BYTE ARRAY FROM ANOTHER BYTE ARRAY DOESN'T WORK
I'm try also using Response method, but I can't find BinaryWrite() on the ASPNET CORE overloads of Response... nothing also using a MemoryStream! Can you help me please..?
Read the comment of Stephen Muecke for understand what has been my issue.
public FileContentResult Download(int id)
{
return File(_context.myTable.Find(id).MyBLOBField,
_context.myTable.Find(id).MyFieldContentType,
_context.Richieste.Find(id).MyFieldOriginalFileName
);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.