Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple files not working properly #49

Open
RoosterH opened this issue Nov 14, 2020 · 2 comments
Open

Multiple files not working properly #49

RoosterH opened this issue Nov 14, 2020 · 2 comments

Comments

@RoosterH
Copy link

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!

@RoosterH RoosterH changed the title Multiple Sizes with different Keys and file naming convention Multiple files not working properly Nov 14, 2020
@GabrielBB
Copy link

I'm having this same problem still in 2022

@tigading
Copy link

tigading commented Oct 5, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants