Skip to content

Commit 03ef1bf

Browse files
committed
Add Content-Type to the images uploaded to AWS S3
1 parent 5343a61 commit 03ef1bf

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

app.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,9 @@ app.post('/uploadimage', function (req, res) {
548548
Body: buffer
549549
}
550550

551+
var mimeType = getImageMimeType(files.image.path)
552+
if (mimeType) { params.ContentType = mimeType }
553+
551554
s3.putObject(params, function (err, data) {
552555
if (err) {
553556
logger.error(err)

lib/utils.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,23 @@
33
exports.isSQLite = function isSQLite (sequelize) {
44
return sequelize.options.dialect === 'sqlite'
55
}
6+
7+
exports.getImageMimeType = function getImageMimeType (imagePath) {
8+
var fileExtension = /[^.]+$/.exec(imagePath)
9+
10+
switch (fileExtension[0]) {
11+
case "bmp":
12+
return "image/bmp"
13+
case "gif":
14+
return "image/gif"
15+
case "jpg":
16+
case "jpeg":
17+
return "image/jpeg"
18+
case "png":
19+
return "image/png"
20+
case "tiff":
21+
return "image/tiff"
22+
default:
23+
return undefined
24+
}
25+
}

0 commit comments

Comments
 (0)