Skip to content

Instantly share code, notes, and snippets.

@leemartin

leemartin/sign.js

Created Aug 10, 2019
Embed
What would you like to do?
Get presigned upload url for S3 compatible with Uppy and Netlify Functions
const AWS = require('aws-sdk')
const s3 = new AWS.S3({
accessKeyId: process.env.AWS_KEY,
secretAccessKey: process.env.AWS_SECRET,
useAccelerateEndpoint: true
})
const getSignedUrlPromise = (operation, params) => {
return new Promise((resolve, reject) => {
return s3.getSignedUrl(operation, params, (err, url) => {
return err ? reject(err) : resolve(url)
})
})
}
exports.handler = async (event, context) => {
const key = event.queryStringParameters.key
try {
const url = await getSignedUrlPromise('putObject', {
Bucket: process.env.S3_BUCKET,
ContentType: 'image/jpeg',
Key: key
}).catch((err) => console.log(err))
return {
statusCode: 200,
body: JSON.stringify({
method: 'PUT',
url: url,
fields: []
})
}
} catch (err) {
console.log(err)
return {
statusCode: 500,
body: 'NOT OK'
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.