Skip to content

Instantly share code, notes, and snippets.

@sidharrth2002
Created December 19, 2021 15:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sidharrth2002/5b09ce1b3bd1af670a27568a74fb8e7d to your computer and use it in GitHub Desktop.
Save sidharrth2002/5b09ce1b3bd1af670a27568a74fb8e7d to your computer and use it in GitHub Desktop.
let randomFileName = uuidv4() + '.' + req.file.originalname.split('.')[req.file.originalname.split('.').length - 1];
let filename = req.file.originalname;
sharp(req.file.buffer)
.jpeg({
quality: 30,
})
.withMetadata()
.rotate()
.toBuffer()
.then((data) => {
minioClient.putObject('reports', randomFileName, data, function(err, etag) {
if(err) {
res.status(500).send({
message: err,
status: 'failed to upload to minio'
})
} else {
res.status(200).send({
message: etag,
status: `${randomFileName} uploaded successfully`,
secure_url: minioClient.protocol + '//' + minioClient.host + ':' + minioClient.port + '/reports/' + randomFileName
})
}
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment