Skip to content

Instantly share code, notes, and snippets.

@maticzav
Last active December 29, 2017 13:49
Show Gist options
  • Save maticzav/869284531280470ef84379fd17f3680b to your computer and use it in GitHub Desktop.
Save maticzav/869284531280470ef84379fd17f3680b to your computer and use it in GitHub Desktop.
// src/index.ts
import { S3 } from 'aws-sdk'
// Creates S3 client
const s3client = new S3({
accessKeyId: process.env.S3_KEY,
secretAccessKey: process.env.S3_SECRET,
params: {
Bucket: process.env.S3_BUCKET
}
})
// src/modules/fileApi.ts
// Uploads a file to S3
const response = await s3.upload({
Key: secret,
ACL: 'public-read',
Body: part,
ContentLength: size,
ContentType: contentType
}).promise()
// Saves untraceable url for database synchronisation
const url = response.Location
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment