Search
 
SCRIPT & CODE EXAMPLE
 

TYPESCRIPT

nodejs aws s3 upload

import multer from 'multer'
import multerS3 from 'multer-s3'
import aws from 'aws-sdk'
import { Request } from 'express'

aws.config.update({
	accessKeyId: process.env.AWS_ACCESS_KEY_ID,
	secretAccessKey: process.env.AWS_ACCESS_KEY
})

export class Multer {
	public static upload = multer({
		storage: multerS3({
			s3: new aws.S3(),
			bucket: process.env.AWS_BUCKET_NAME,
			contentType: multerS3.AUTO_CONTENT_TYPE,
			serverSideEncryption: 'AES256',
			acl: 'public-read',
			key: function (request: Request, file: Express.Multer.File, done: any) {
				const fileName: string = `${Date.now().toString()} - ${file.originalname}`
				done(null, fileName)
			}
		}),
		fileFilter: (req: Request, file: Express.Multer.File, done: any) => {
			if (!mimeTypeSupport(file.mimetype)) throw new TypeError('mimetype not supported')
			const fileName: string = `${Date.now().toString()} - ${file.originalname}`
			done(null, fileName)
		}
	}).array('upload', 100)
}
Comment

PREVIOUS NEXT
Code Example
Typescript :: javascript audio delay 
Typescript :: pros and cons? 
Typescript :: number of elements in list in python 
Typescript :: swal fire 
Typescript :: pandas check if row exists in another dataframe 
Typescript :: split list into sublists with linq 
Typescript :: how to define an array type in typescript 
Typescript :: angular currency pipe pt-br as variable 
Typescript :: Array.prototype.map() expects a return value from arrow function array-callback-return 
Typescript :: typescript compile on save 
Typescript :: how to check if data attribute exists in jquery 
Typescript :: get random light color 
Typescript :: create mock promise angular 
Typescript :: provider in ethers.js 
Typescript :: python convert long floats to usd 
Typescript :: await constructor typescript 
Typescript :: calling contract method 
Typescript :: typescript parameter function type 
Typescript :: props vue typescript 
Typescript :: available ports for localhost 
Typescript :: how to remove the last item from a collection powerapps 
Typescript :: inno add exe in service 
Typescript :: remove showing results woocommerce shortcode 
Typescript :: intrinsicattributes typescript 
Typescript :: laravel validation exists multiple tables laravel 
Typescript :: jsdoc to typescript 
Typescript :: jest not toBe 
Typescript :: react components for login 
Typescript :: cacerts default password 
Typescript :: typescript generic type 
ADD CONTENT
Topic
Content
Source link
Name
4+6 =