Best way to design file upload API

45 views
Skip to first unread message

Ratnadeep Deshmane

unread,
Oct 30, 2012, 11:28:10 AM10/30/12
to bangal...@googlegroups.com
Hello All,

In one of my rails app, I want to create public API, where people can upload files.

This web app is hosted on heroku and files are being stored in s3, also maximum file size is 100mb now, which may increase later. So, I have created API as - 

1. /get_access_key - this request by client will get it time valid access_key, file upload location and other details.
2. client will use results from step 1 to upload file directly to s3
3. client will be redirected to web app by s3 after upload. Web app will validate recent uploaded file and respond accordingly.

So, it take two request to upload a file to s3 and one more request by client to update text details for uploaded asset.

Problem is - in all it takes 3 https request with this API design to upload file and add text details.

Anybody knows any other better way to do this ?


Akshay Gupta

unread,
Nov 7, 2012, 5:16:47 AM11/7/12
to bangal...@googlegroups.com
Hi Ratandeep,

I can think of combining last two steps into one.

1. Step basically provides a one time usable or time valid access_key or authentication_token
2. Let the request directly come to your web app with this access_key, file to be uploaded, text details about the asset to be uploaded.
Now, first validate the file format, size, access_key etc and then upload the file to S3 from web app using AWS-SDK gem and respond back with the file upload details or any encountered errors.


regards,

Akshay Gupta
Mob: +91-971-133-5593

--
 
 

Ratnadeep Deshmane

unread,
Nov 7, 2012, 5:41:54 AM11/7/12
to bangal...@googlegroups.com
Thanks Akshay!

I ended up doing it that way only.

First step - to get authentication token and other params.
Second step - a request to s3 for for file upload. On successful upload, s3 redirects request to my app again, where I do validations and return results.

I wanted to avoid getting files directly on my app, as for longer file sizes, it used to go beyond timeout time and also eat up a thread.
--
 
 

Reply all
Reply to author
Forward
0 new messages