ikhsanalatsary/multer-sharp-s3

Multiple files not working properly

RoosterH opened this issue · 2 comments

Hi,

Thanks very much for creating this wonderful package.
I tried it with multiple sizes yesterday. It worked when the request has one file. When there are multiple files, it doesn't seem to work.

In router, I am using:

fileUploadResizeS3.fields([
	{ name: 'eventImage', maxCount: 1 },
	{ name: 'courseMap', maxCount: 1 }
]),

fileUploadResizeS3 is where I define multer-sharp-s3:

const fileUploadResizeS3 = multer({
	limits: 1500000, 
	storage: s3Storage({
		ACL: 'public-read', 
		s3: s3,
		Bucket: process.env.S3_BUCKET_NAME,
		metadata: (req, file, cb) => {
			const ext = MIME_TYPE_MAP[file.mimetype];
			cb(null, { fieldName: file.fieldname });
		},
		Key: (req, file, cb) => {
			const UUID = uuid();
			const ext = MIME_TYPE_MAP[file.mimetype];

			let S3Folder;
                          .........

			cb(null, S3Folder + '/' + UUID + '.jpg');
		},
		multiple: true,
		resize: [{ suffix: 'small', width: 300 }, { suffix: 'original' }],
		toFormat: { type: 'jpeg', options: { quality: 100 } }
	}),
	fileFilter: (req, file, cb) => {
		const isValid = !!MIME_TYPE_MAP[file.mimetype];
		let error = isValid ? null : new Error('Invalid MIME type!');
		cb(error, isValid);
	}
});

It did return 2 file arrays:

req.files =  [Object: null prototype] {
  eventImage: [
    {
      fieldname: 'eventImage',
      originalname: 'Bowser.jpg',
      encoding: '7bit',
      mimetype: 'image/jpeg',
      small: [Object],
      original: [Object]
    }
  ],
  courseMap: [
    {
      fieldname: 'courseMap',
      originalname: 'CourseMap.png',
      encoding: '7bit',
      mimetype: 'image/png',
      small: [Object],
      original: [Object]
    }
  ]
}

The problem is files inside of eventImage are actually coureMap files. CourseMap files are empty, 0 byte.

Please look into this issue and let me know if you need more information.

Thanks again!

I'm having this same problem still in 2022

I'm having this same problem still in 2022. Please support to fix it!! Thank you very much!!