Skip to content

Instantly share code, notes, and snippets.

@weaver
Created October 2, 2012 15:31
Show Gist options
  • Save weaver/3820194 to your computer and use it in GitHub Desktop.
Save weaver/3820194 to your computer and use it in GitHub Desktop.
S3 Upload Example

S3 Upload Example

This example demonstrates how to upload a file directly to S3 from a browser. The Node server generates a policy and signature, authorizing the upload.

Once a file has been successfully uploaded, S3 redirects the browser to a Node callback url.

Get Started

To get started:

npm install
export AWS_KEY='your-aws-key'
export AWS_SECRET='your-key-secret'
export S3_BUCKET='your-bucket-name'
node app.js

Uploaded Files

Files are uploaded into example/{{uuid}}/filename.ext. By default, S3 will serve uploaded files as application/octet-stream. Pass a contentType parameter to choose a more specific type. For example:

open http://localhost:3000/?contentType=text/html

The policy generated for the upload allows any content type, so the Content-Type could also be set client side.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment