How to convert FileStreamResult to IFormFile?

Viewed 21518

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");
    }
}
2 Answers

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);
    }
}
Related