0

I am developing a RESTFUL app using Asp.Net Web Api 2 and Angularjs. I have never done image upload the way I am planning to do and I would appreciate if someone could educate me a little bit, giving me examples or at least an article to start with.

What exactly I want to do is the following: 1. being able to upload multiple images at ones, with their preview appearing on the browser before the whole record is saved in the database. 2. I want the pictures to be stored on the disk directly, but their path should be saved in the database as a string.

I need help for both server side and client side development of it. On the client side, any Angularjs or JQuery library is acceptable.

1 Answer 1

2

Hi you need to create a Multipart Formatter to support multiple files upload. Example here

In the example they have a e2e example, writing the images on the disk. You just need to adapt to write the fileUrl in the DB.

I never uploaded images with AngularJs but this library looks great.

edit: Here is a example of a Multipart Request, it's necessary to define a boundary to separate the images. Attention the last boundary should have a prefix -- to mark the end of the request.

POST http://yourendpoint/api/images HTTP/1.1
Content-Type: multipart/form-data; boundary=--YourBoundary

----YourBoundary
Content-Disposition: form-data; name="image1"; filename="image1.gif"
Content-Type: image/gif

ImageBytes...asodnaoisdaisndaosind
Content-Disposition: form-data; name="image2"; filename="image2.png"
Content-Type: image/png

ImageBytes...asodnaoisdaisndaosind
----YourBoundary
Content-Disposition: form-data; name="image3"; filename="image3.jpg"
Content-Type: image/jpg

ImageBytes...asodnaoisdaisndaosind
----YourBoundary--
Sign up to request clarification or add additional context in comments.

Comments

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.