Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute:

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.

share|improve this question

1 Answer 1

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--
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.