Skip to content

Node.js based forum software built for the modern web

closes #4645

barisusakli630dd66cf6a7
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, {