ikhsanalatsary/multer-sharp-s3

Node.js multer-sharp-s3 working locally but error on Heroku: Error: Input buffer contains unsupported image format

tntn123 opened this issue · 2 comments

I was able to run this locally with following code, but when I pushed it to Heroku, it gives below error.

Error: Input buffer contains unsupported image format

Code:

const aws = require('aws-sdk')
const { v4: uuidv4 } = require('uuid');

aws.config.update({
secretAccessKey: process.env.AWS_ACCESS_KEY,
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
region: process.env.AWS_LOCATION,
})

const s3 = new aws.S3()

const s3Storage = require('multer-sharp-s3')
const MIME_TYPE_MAP = {
'image/png': 'png',
'image/jpeg': 'jpg',
'image/jpg': 'jpg',
}

const storage = s3Storage({
s3: s3,
Bucket: process.env.AWS_BUCKET_NAME,
Key: function(req, file, cb) {
console.log(file)
const isValid = MIME_TYPE_MAP[file.mimetype]
let error = new Error('Invalid mime type')
if (isValid) {
error = null
}
cb(error,${process.env.AWS_BUCKET_NAME}/places/${uuidv4()})
},
ACL: 'public-read',
multiple: true,
resize: {
width: 400,
height: 400,
},
})

const upload = multer({ storage })

Solved by downgrading sharp from 0.26.1 to 0.25.1 , this is a Sharp problem with the latest library.

Hi @tntn123, thanks for addressing this issue. I think you need to make sure your node version on Heroku.