I using the file input component to store files in an MSSQL db table.
The db field is nvarchar(max)
I can input the file and I can see the string starts data:application/pdf;base64,JVBERi0xLjcN
When I try and download it I get an error.
My code to download this file is:
public async Task<IActionResult> OnPostDownloadAsync(int? id)
{
var myDoc = dbContext.TblDocuments.FirstOrDefault(m => m.DocumentID == id);// rDefaultAsync(m => m.Id == id);
if (myDoc == null)
{
return NotFound();
}
if (myDoc.Document == null)
{
return null;
}
else {
byte[] byteArr = Encoding.UTF8.GetBytes(myDoc.Document);
string mimeType = "application/pdf";
return new FileContentResult(byteArr, mimeType)
{
FileDownloadName = $"Invoice {myDoc.DocumentName}.pdf"
};
}
}
What is the decode format I need?
I have tried:
- Convert.FromBase64 with and without removing the characters up to the comma,
- ASCII but my PDF viewer either renders and empty page and says there is an error or I get a full blown webpage error.
Thanks John