Merge pull request #4572 from pichalite/image-upload

fix image upload in post
v1.18.x
Barış Soner Uşaklı 9 years ago
commit 58ea83014c

@ -6,6 +6,7 @@ var async = require('async');
var nconf = require('nconf'); var nconf = require('nconf');
var validator = require('validator'); var validator = require('validator');
var winston = require('winston'); var winston = require('winston');
var mime = require('mime');
var meta = require('../meta'); var meta = require('../meta');
var file = require('../file'); var file = require('../file');
@ -171,9 +172,14 @@ function uploadFile(uid, uploadedFile, callback) {
} }
function saveFileToLocal(uploadedFile, callback) { function saveFileToLocal(uploadedFile, callback) {
var extension = path.extname(uploadedFile.name);
if(!extension) {
extension = '.' + mime.extension(uploadedFile.type);
}
var filename = uploadedFile.name || 'upload'; var filename = uploadedFile.name || 'upload';
filename = Date.now() + '-' + validator.escape(filename).substr(0, 255); filename = Date.now() + '-' + validator.escape(filename.replace(extension, '')).substr(0, 255) + extension;
file.saveFileToLocal(filename, 'files', uploadedFile.path, function(err, upload) { file.saveFileToLocal(filename, 'files', uploadedFile.path, function(err, upload) {
if (err) { if (err) {
return callback(err); return callback(err);

Loading…
Cancel
Save