Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

nestjs multer file upload delay

export class Multer {
	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(request: Request, file: Express.Multer.File, done: any) {
				const fileName: string = `${Date.now().toString()} - ${file.originalname}`
				done(null, fileName)
			}
		}),
		storage: multer.diskStorage({
			destination(_: Request, file: Express.Multer.File, done: any) {
				let linux: string = `${process.env.IMG_DIR}`
				let window: string = process.env.TEMP || ''

				if (!file) {
					done(new Error('Uploading file failed'), null)
				} else {
					if (process.platform === 'win32') {
						if (fs.existsSync(window)) {
							done(null, window)
						} else {
							done(new Error('No such file directory').message, null)
						}
					} else {
						if (fs.existsSync(linux)) {
							done(null, linux)
						} else {
							done(new Error('No such file directory').message, null)
						}
					}
				}
			},
			filename(_, file, done: any) {
				if (!file) done(new Error('Get file upload failed'), null)
				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')
			if (file.size >= 5242880) throw new TypeError('maximum file or image size must be 5 MB or under 5 MB')

			const fileName: string = `${Date.now().toString()} - ${file.originalname}`
			done(null, fileName)
		},
		limits: { fileSize: 5242880 }
	}).array('upload', 2)
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: link js filt to html file 
Javascript :: how to call javascript function in p tag 
Javascript :: gsap cdn not working 
Javascript :: $(document).ready(function () { $(".inputs").click(function () { alert($(this).id); }); }); 
Javascript :: how to make a dot function javascript 
Javascript :: _document getInitialProps req is undefined 
Javascript :: binary function 
Javascript :: when i add data into the input it disappeared in react 
Javascript :: javascript random letters and numbers 
Javascript :: how to render req.session.name to ejs 
Javascript :: get last day of month js 
Javascript :: Getting current location from browser Chrome and Firefox console 
Javascript :: convert object to array online javascript 
Javascript :: parse and stringify dom element in js 
Javascript :: Star Wars Celebration 
Javascript :: compare strings to multiple strings javascript 
Javascript :: converting jsObject to JSON 
Javascript :: JS in JSX. Whenever you need to add some JS, just put it inside curly braces {} 
Javascript :: react axios POST with super constructor parent class 
Javascript :: find result using type: mongoose.Schema.ObjectId, 
Javascript :: convert js to tsx 
Javascript :: react native leaflet 
Javascript :: kayengxiong promise js 
Javascript :: Minimum Path Sum Rec 
Javascript :: react-inline-script 
Javascript :: repeater javascript 
Javascript :: find leap year javascript 
Javascript :: javascript$.4908BEAMpacidE 
Javascript :: @typescript-eslint/no-empty-function 
Javascript :: mui datatable onrowdelete 
ADD CONTENT
Topic
Content
Source link
Name
1+8 =