Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

bradleyg/s3cors

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

##s3cors

###Direct uploads to Amazon S3 via CORS.

First setup a CORS policy on your S3 bucket.

<CORSConfiguration>
    <CORSRule>
        <AllowedOrigin>*</AllowedOrigin>
        <AllowedMethod>PUT</AllowedMethod>
        <AllowedMethod>POST</AllowedMethod>
        <AllowedMethod>GET</AllowedMethod>
        <MaxAgeSeconds>3000</MaxAgeSeconds>
        <AllowedHeader>*</AllowedHeader>
    </CORSRule>
</CORSConfiguration>

Create your form fields:

var s3cors = require('s3cors') 

var formFields = s3cors.create({
  "key": "AWS_KEY",
  "secret": "AWS_SECRET",
  "bucket": "AWS_BUCKET",
  "acl": "public-read",
  "region": "eu-west-1"
})

This will return a URL to post to (formFields.url) and a dictionary of values (formFields.data) to append to your upload form. In your html the file input field must be named "file".

<form action="{{ formFields.url }}" method="POST">
  <input type="file" name="file"></imput>
  
  {% formFields.data.forEach(function(key){ %}
    <input type="hidden" name="{{ key }}" value="{{ formFields[key] }}">  
  {% }) %}
</form>

Tests: npm test Install: npm install s3cors

Build Status

About

Direct CORS uploads to S3.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published