The HW Blog

Want to be updated? @opencoconut | Feed

Uploading videos directly to Amazon S3

Bruno Celeste (@brunoceleste)

April 01, 2014 Tech

It's pretty straightforward thanks to Amazon, you can now save some bandwidth and allow your user to upload directly to your S3 bucket.

Here is a very simple example:

<form action="" method="post" enctype="multipart/form-data">
<input type="hidden" name="key" value="<%= %>/videos/<%= random_key %>" /><br />
<input type="hidden" name="acl" value="public-read" />
<input type="hidden" name="x-amz-meta-uuid" value="14365123651274" />
<input type="hidden" name="redirect" value="<%= %>" >
<input type="hidden" name="AWSAccessKeyId " value="15B4D3461F177624206A" />
<input type="hidden" name="Policy" value="eyAiZXhwaXJhdGlvbiI6ICIy..." />
<input type="hidden" name="Signature" value="2qCp0odXe7A9IYyUVqn0w2adtCA=" />
Video file <input type="file" name="file" /> <br />
<input type="submit" name="submit" value="Upload to Amazon S3" />

When an user upload the file to your bucket, the response will be:

HTTP/1.1 303 Redirect
x-amz-request-id: 1AEE782442F35865
x-amz-id-2: cxzFLJRatFHy+NGtaDFRR8YvI9BHmgLxjvJzNiGGICARZ/mVXHj7T+qQKhdpzHFh
Content-Type: application/xml
Date: Wed, 14 Nov 2007 21:21:33 GMT
Connection: close
Server: AmazonS3

In upload_ok page, you'll makethe request to Coconut to transfer and encode the video:

user = User.find(params[:user_id])
url = "{params[:key]}"

hw ="HW-API-Key", api_key) :create :url => url

See the S3 documentation.

Any Comment? Contact us via our contact page