0

So, I'm quite new to the ASP.NET MVC framework. What I need to do is make an API endpoint for a webserver which accepts a HTTP post request that has an image file uploaded to it.

I've looked around and I'm really not sure how to handle this. The closest I've come is this resource: File Upload and Multipart MIME - ASP.NET Web API

Is this pretty much the only way to do it?

1 Answer 1

1

No, you can also send it across as a class that has a string property that contains the base64 encoded contents of the file. You then have to decode the base64 in the web api method (which is still a post) and then save or use the file bytes.

From the client's stand point, the most straight-forward way of doing it is multipart mime. But your question was about web api, and it can handle base64 in say, a json object just fine.

If you don't use multipart mime you'll need javascript that converts the upload into base64. That part of it is beyond the scope of your question.

But strictly speaking multipart is not the only way because I had such a javascript file upload library and that's what I used and it worked fine.

The reason why we used that component was because we wanted thumbnail upload preview of the images (preview first), then a submit button to actually submit to web api. javascript held the images in localstorage until the user hit submit (was a multiple image upload thing).

Sign up to request clarification or add additional context in comments.

1 Comment

Cheers mate! :) I just wanted to make sure it was an okay solution for a production environment, but from what I can see on MSDN blogs, it seems to be a good scaleable way to do it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.