'Is there a way to get an Image from a path on the server and pass it into an IFormFile variable or property?

I need to get an image(IFormFile) which is stored on the server in a folder to a controller making the request. I have a model which contains a Logo as an IFormFile like below:

public IFormFile Logo { get; set; }

Logo is in a Model called Label and there are multiple fields in there. My goal is to send the whole model and then append the IFormFile to the label object and specifically to the Logo property and send it altogether to the other end. Is there a way i can achieve this?

 Stream outStream = System.IO.File.OpenWrite(Path.Combine("wwwroot//labels//IMG_20190322_180828.jpg"));
var label = _database.Labels.Where(d => d.Id == labelId).FirstOrDefault();
            label.Logo = (IFormFile)outStream;
            return Ok(label);

I know i cannot convert a stream to an IFormFile but i wrote it here for demo. I can get the file in a stream as above but how do i append it to the Logo or is there a better way i can send an image?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source