Search
 
SCRIPT & CODE EXAMPLE
 

TYPESCRIPT

multer s3

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 :: query orders by products woocommerce 
Typescript :: How to specify output directory in TypeScript? 
Typescript :: typescript get the time moment 
Typescript :: subplots matplotlib 
Typescript :: mixed array typescript 
Typescript :: angular formgroup validate manually 
Typescript :: extend typescript 
Typescript :: typescript arr numbers and strings 
Typescript :: typescript api request header 
Typescript :: typescript list concat 
Typescript :: Prevent anchor tag to move to up when we click on it 
Typescript :: what are google extensions 
Typescript :: union types typescript 
Typescript :: json to object typescript 
Typescript :: google sheets countif two conditions 
Typescript :: nestjs mongoose schema 
Typescript :: calling contract from ethereum 
Typescript :: pass function as argument typescript 
Typescript :: typescript object get value by key 
Typescript :: google sheets format number as duration formula 
Typescript :: rails assets precompile with staging flag command 
Typescript :: angular animation done event type typescript 
Typescript :: tsconfig.json, Typescript 
Typescript :: two absolute elements are overlapping css help 
Typescript :: Index signature property 
Typescript :: download toasts in django 
Typescript :: jest not tocontain 
Typescript :: angular images 
Typescript :: download blob typescript 
Typescript :: nullish coalescing typescript 
ADD CONTENT
Topic
Content
Source link
Name
8+8 =