.Net web api - returning image with a message

Viewed 33

I am preparing CRUD endpoint for posts (like from social media) in my API (.NET 6, Swagger UI, MongoDb). POST endpoint takes string message and IFormFile with image and save it in db - image is being saved as byte array. User could send a post only with message, only with image or with both of them in the same time. Everything went smoth till the GET endpoint.

In case of returning one of them its fine. In case of returing both the message and the image there is a problem, because I cannot return FileContentResult with image in the same time with string message. I was about to return the message in response header, but I am not sure if its a good idea. Other possible way is to just return message property and image as e.g. stirng. One other way is to just temporarly store the image phisically and send just an url to it. I am not convinced to any of the solutions I figured out.

Could you please tell me, how you see it? Maybe you have faced similar situation in the past? Kind regards

0 Answers
Related