I change the size of the image with this code. But this method returns FileStreamResult
. I want to convert FileStreamResult
to IFromFile
. How can I do that?
Note: I am using CoreCompat to change the image size.
public FileStreamResult ChangeSize(IFormFile file)
{
using (var img = System.Drawing.Image.FromStream(file.OpenReadStream()))
{
Stream ms = new MemoryStream(img.Resize(100, 100).ToByteArray());
return new FileStreamResult(ms, "image/jpg");
}
}
What is IFormFile. ASP.NET Core has introduced an IFormFile interface that represents transmitted files in an HTTP request. The interface gives us access to metadata like ContentDisposition, ContentType, Length, FileName, and more. IFormFile also provides some methods used to store files.
FileContentResult. Represents an ActionResult that when executed will write a binary file to the response. FileStreamResult. Represents an ActionResult that when executed will write a file from a stream to the response.
This works for the file but it doesn't appear to copy other data, such as the content type
public IFormFile GetFormFile(FileStreamResult fsr)
{
using (var fs = fsr.FileStream)
{
file = new FormFile(fs, 0, fs.Length, "name", fsr.FileDownloadName);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With