Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to upload multiple files as part of a REST API? Single or multiple POST requests?

I am trying to create a REST API for my web service.

I want to make the users of the API able to initiate a new request with my service. This involves uploading one or two zip files along with some other parameters.

How can I make this all combined into one request? Or is it better to do it multiple requests somehow?

I don't have a lot of familiarity with making REST APIs so I don't know how people usually do it.

I'm using PHP for my site if that matters.

like image 294
dcarr622 Avatar asked Aug 12 '13 07:08

dcarr622


1 Answers

To do this, you'd need your client to upload in mime/multipart format. I don't know PHP, but I'm sure there's a library out there that will support receiving/parsing the multipart messages you get.

As for whether it's a good idea .. If initiating the request is the creation of a single resource, it's not unreasonable to accept mime/multipart. If the parts being sent are themselves full-fledged resources, it would probably be better to make the client send them up separately, and reference them in the initiation request. Also note that mime/multipart is going to be a bit harder for your clients to deal with than simple requests.

This post seems to be related to what you're trying to accomplish.

like image 191
Eric Stein Avatar answered Sep 19 '22 22:09

Eric Stein