I'm bulding this android app where I need to send images to the server. I'm using retrofit to do so. I get image path as it's answer in this stack overflow question Get file path of image on Android and send images as shown here How to upload an image file in Retrofit 2. When I decode file that I create in android studio it is valid, but when I send it to my .net rest api it is null. Here is my rest api code, the idea is to get image if it's null send image that say's it's null and if not save that image and send it back. The part where I'm sending it back works perfectly, that is I recive image sent to android, but the image that is sent from android is null.
[HttpPost]
[Route("post")]
public async Task<IActionResult> PostSlika(IFormFile formFile)
{
if (formFile is null)
{
var stream2 = new FileStream(Path.Combine(_host.WebRootPath, "Images/null_je.jpg"), FileMode.Open);
return File(stream2, "image/jpg");
}
using (var stream = System.IO.File.Create(Path.Combine(_host.WebRootPath, "Images/1.jpg")))
{
await formFile.CopyToAsync(stream);
}
var stream1 = new FileStream(Path.Combine(_host.WebRootPath, "Images/1.jpg"), FileMode.Open);
return File(stream1, "image/jpg");
}
}