Skip to content

Node.js based forum software built for the modern web

closes #4917

barisusakliaac0313f2eb8
diff --git a/app.js b/app.js
index 1fd183757f..6fd215ad61 100644
--- a/app.js
+++ b/app.js
@@ -121,7 +121,7 @@ function start() {
nconf.set('use_port', !!urlObject.port);
nconf.set('relative_path', relativePath);
nconf.set('port', urlObject.port || nconf.get('port') || nconf.get('PORT') || 4567);
- nconf.set('upload_url', '/uploads/');
+ nconf.set('upload_url', nconf.get('upload_path').replace(/^\/public/, ''));
if (nconf.get('isPrimary') === 'true') {
winston.info('Time: %s', (new Date()).toString());
diff --git a/src/controllers/uploads.js b/src/controllers/uploads.js
index 11c75fd7f9..468e211f9f 100644
--- a/src/controllers/uploads.js
+++ b/src/controllers/uploads.js
@@ -96,24 +96,21 @@ function uploadAsFile(req, uploadedFile, callback) {
}
function resizeImage(fileObj, callback) {
- var fullPath;
async.waterfall([
function(next) {
- fullPath = path.join(nconf.get('base_dir'), nconf.get('upload_path'), '..', fileObj.url);
-
- image.size(fullPath, next);
+ image.size(fileObj.path, next);
},
function (imageData, next) {
if (imageData.width < (parseInt(meta.config.maximumImageWidth, 10) || 760)) {
return callback(null, fileObj);
}
- var dirname = path.dirname(fullPath);
- var extname = path.extname(fullPath);
- var basename = path.basename(fullPath, extname);
+ var dirname = path.dirname(fileObj.path);
+ var extname = path.extname(fileObj.path);
+ var basename = path.basename(fileObj.path, extname);
image.resizeImage({
- path: fullPath,
+ path: fileObj.path,
target: path.join(dirname, basename + '-resized' + extname),
extension: extname,
width: parseInt(meta.config.maximumImageWidth, 10) || 760
@@ -223,6 +220,7 @@ function saveFileToLocal(uploadedFile, callback) {
var filename = uploadedFile.name || 'upload';
filename = Date.now() + '-' + validator.escape(filename.replace(extension, '')).substr(0, 255) + extension;
+
file.saveFileToLocal(filename, 'files', uploadedFile.path, function(err, upload) {
if (err) {
return callback(err);
@@ -230,6 +228,7 @@ function saveFileToLocal(uploadedFile, callback) {
callback(null, {
url: nconf.get('relative_path') + upload.url,
+ path: upload.path,
name: uploadedFile.name
});
});
diff --git a/src/file.js b/src/file.js
index 001e1324cb..3920b3c271 100644
--- a/src/file.js
+++ b/src/file.js
@@ -1,12 +1,12 @@
"use strict";
-var fs = require('fs'),
- nconf = require('nconf'),
- path = require('path'),
- winston = require('winston'),
- jimp = require('jimp'),
+var fs = require('fs');
+var nconf = require('nconf');
+var path = require('path');
+var winston = require('winston');
+var jimp = require('jimp');
- utils = require('../public/src/utils');
+var utils = require('../public/src/utils');
var file = {};
@@ -29,7 +29,8 @@ file.saveFileToLocal = function(filename, folder, tempPath, callback) {
is.on('end', function () {
callback(null, {
- url: nconf.get('upload_url') + folder + '/' + filename
+ url: path.join(nconf.get('upload_url'), folder, filename),
+ path: uploadPath
});
});