BlazorInputFile
BlazorInputFile copied to clipboard
Immidiately use Image
Hey Steve, I've been using your library and I think it's great!
I've been wanting to use it recently to immediately display an image on the page.
From what I've been reading I'd need to set src attribute on an tag to be :
"window.URL.createObjectURL(fileObj);"
Where fileObj is the file that is uploaded through the BlazorInputFile.
Do you have any idea to how I might reference the file object that is retrieved with BlazorInputFile ?
@kevinruder You can write the image to a temporary file location and then serve it that way...
public async Task<string> SaveTempFile(byte[] content)
{
try
{
Directory.CreateDirectory("/tmp");
var tempFileName = Path.GetTempFileName();
await using (var writer = File.OpenWrite(tempFileName))
{
await writer.WriteAsync(content);
}
return Path.GetFileName(tempFileName);
}
catch (Exception e)
{
_logger.LogError($"Failed to Save File! Error: {e}");
throw;
}
}