Hey devs!After several tutorials and questions found on SO, I came here for help. :PI have an API where I can send pictures to my bucket at S3. Everything is working fine, but when I upload a GIF, it doesn't work. The size is smaller than the original gif.I am using multer, aws-sdk, and multer-sharp-s3.Does anyone have any idea of what could be causing this? If I manually upload the same gif, it works!My code:const s3 = new aws.S3({ accessKeyId: process.env.AWS_ACCESS_KEY_ID, secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY, }); const multerFilter = (req, file, cb) => { if (file.mimetype.startsWith("image")) { cb(null, true); } else { cb(new Error("Not an image! Please upload only an image."), false); } }; const upload = multer({ fileFilter: multerFilter, storage: multerSharp({ Key: (req, file, cb) => { const userId = `${req.user[0].login}`; const todaysDate = `-${Date.now().toString()}.`; const extension = file.mimetype.split("/")[1]; const finalStr = userId.concat(todaysDate, extension); const fullPath = "projects/" + userId + "/" + finalStr; cb(null, fullPath); }, s3, Bucket: process.env.AWS_BUCKET_NAME, ACL: "public-read", resize: { width: 1135, height: 715, }, }), }); Reading the docs for multer-sharp, they have a toFormat param, and they say that you can set up as "gif", but when I try, I got this error on my server:throw is.invalidParameterError('format', `one of: ${[...formats.keys()].join(', ')}`, format); ^ Error: Expected one of: heic, heif, jpeg, jpg, png, raw, tiff, webp for format but received gif of type string Thank you all!
Submitted July 24, 2020 at 01:38AM by lucasmrl
No comments:
Post a Comment