From 630dd66cf6a72929e6a75c7406a89b3019d5f0b3 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Sun, 15 May 2016 21:18:05 +0300 Subject: [PATCH] closes #4645 --- src/controllers/uploads.js | 2 +- src/groups/cover.js | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/controllers/uploads.js b/src/controllers/uploads.js index 087889d340..16bc3b7c31 100644 --- a/src/controllers/uploads.js +++ b/src/controllers/uploads.js @@ -198,7 +198,7 @@ function uploadFile(uid, uploadedFile, callback) { function saveFileToLocal(uploadedFile, callback) { var extension = path.extname(uploadedFile.name); - if (!extension) { + if (!extension && uploadedFile.type) { extension = '.' + mime.extension(uploadedFile.type); } diff --git a/src/groups/cover.js b/src/groups/cover.js index 89ef97df94..99f2791a2e 100644 --- a/src/groups/cover.js +++ b/src/groups/cover.js @@ -6,6 +6,7 @@ var path = require('path'); var fs = require('fs'); var crypto = require('crypto'); var Jimp = require('jimp'); +var mime = require('mime'); var db = require('../database'); var file = require('../file'); @@ -29,6 +30,7 @@ module.exports = function(Groups) { var tempPath = data.file ? data.file : ''; var url; + var type = data.file ? mime.lookup(data.file) : 'image/png'; async.waterfall([ function (next) { @@ -41,7 +43,8 @@ module.exports = function(Groups) { tempPath = _tempPath; uploadsController.uploadGroupCover(uid, { name: 'groupCover', - path: tempPath + path: tempPath, + type: type }, next); }, function (uploadData, next) { @@ -54,7 +57,8 @@ module.exports = function(Groups) { function (next) { uploadsController.uploadGroupCover(uid, { name: 'groupCoverThumb', - path: tempPath + path: tempPath, + type: type }, next); }, function (uploadData, next) { @@ -104,7 +108,7 @@ module.exports = function(Groups) { md5sum = md5sum.digest('hex'); // Save image - var tempPath = path.join(nconf.get('base_dir'), nconf.get('upload_path'), md5sum); + var tempPath = path.join(nconf.get('base_dir'), nconf.get('upload_path'), md5sum) + '.png'; var buffer = new Buffer(imageData.slice(imageData.indexOf('base64') + 7), 'base64'); fs.writeFile(tempPath, buffer, {