Upload file to s3: make public a file on upload and allow to configure destination folder

New configurations:
- s3folder: (string) folder to save the files inside bucket
- s3publicFiles: (boolean) indicate if should send ACL parameters

Signed-off-by: Lautaro Alvarez <lautarolalvarez@gmail.com>
This commit is contained in:
Lautaro Alvarez 2022-05-25 16:49:32 -03:00 committed by David Mehren
parent 8643d9cc99
commit 3585dc9ee6
4 changed files with 18 additions and 11 deletions

View file

@ -28,12 +28,13 @@ exports.uploadImage = function (imagePath, callback) {
}
const params = {
Bucket: config.s3bucket,
Key: path.join('uploads', path.basename(imagePath)),
Key: path.join(config.s3folder, path.basename(imagePath)),
Body: buffer
}
const mimeType = getImageMimeType(imagePath)
if (mimeType) { params.ContentType = mimeType }
if (config.s3publicFiles) { params.ACL = 'public-read' }
logger.debug(`S3 object parameters: ${JSON.stringify(params)}`)
s3.putObject(params, function (err, data) {