tldraw/apps/www/pages/api/upload.ts
Milo Hill f61c09fb55
Fix SVG's not loading in multiplayer (#498)
* Session undefined

* Fix S3 svg uploads
2022-01-12 13:36:19 +00:00

26 lines
621 B
TypeScript

import aws from 'aws-sdk'
export default async function handler(req, res) {
aws.config.update({
accessKeyId: process.env.TL_AWS_ACCESS_KEY,
secretAccessKey: process.env.TL_AWS_SECRET_KEY,
region: process.env.TL_AWS_REGION,
signatureVersion: 'v4',
})
const s3 = new aws.S3()
const post = s3.createPresignedPost({
Bucket: process.env.TL_AWS_BUCKET_NAME,
Fields: {
key: req.query.file,
'Content-Type': req.query.fileType,
},
Expires: 60, // seconds
Conditions: [
['content-length-range', 0, 5242880], // up to 5 MB
],
})
res.status(200).json(post)
}