Skip to content

Commit 629d301

Browse files
committed
Express 2.x, name Image via url
1 parent 903d628 commit 629d301

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

index.js

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ module.exports = function (options) {
1616
};
1717

1818
options = _.extend({
19-
tmpDir: '/tmp',
19+
tmpDir: __dirname + '/tmp',
2020
uploadDir: __dirname + '/public/files',
2121
uploadUrl: '/files/',
2222
maxPostSize: 11000000000, // 11 GB
@@ -92,11 +92,9 @@ module.exports = function (options) {
9292
};
9393

9494
UploadHandler.prototype.noCache = function () {
95-
this.res.set({
96-
'Pragma': 'no-cache',
97-
'Cache-Control': 'no-store, no-cache, must-revalidate',
98-
'Content-Disposition': 'inline; filename="files.json"'
99-
});
95+
this.res.header('Pragma', 'no-cache');
96+
this.res.header('Cache-Control', 'no-store, no-cache, must-revalidate');
97+
this.res.header('Content-Disposition', 'inline; filename="files.json"');
10098
};
10199

102100
UploadHandler.prototype.get = function () {
@@ -162,6 +160,8 @@ module.exports = function (options) {
162160
fs.unlink(file.path);
163161
return;
164162
}
163+
var _filename = handler.req.query.imgName;
164+
fileInfo.name = _filename ? _filename+path.extname(fileInfo.name) : fileInfo.name;
165165
fs.renameSync(file.path, options.uploadDir + '/' + fileInfo.name);
166166
if (options.imageTypes.test(fileInfo.name) && _.keys(options.imageVersions).length) {
167167
Object.keys(options.imageVersions).forEach(function (version) {
@@ -208,19 +208,15 @@ module.exports = function (options) {
208208
};
209209

210210
return function (req, res, next) {
211-
res.set({
212-
'Access-Control-Allow-Origin': options.accessControl.allowOrigin,
213-
'Access-Control-Allow-Methods': options.accessControl.allowMethods
214-
});
211+
res.header('Access-Control-Allow-Origin', options.accessControl.allowOrigin);
212+
res.header('Access-Control-Allow-Methods', options.accessControl.allowMethods);
213+
215214
var handler = new UploadHandler(req, res, function (result, redirect) {
216215
if (redirect) {
217216
res.redirect(redirect.replace(/%s/, encodeURIComponent(JSON.stringify(result))));
218217
} else {
219-
res.set({
220-
'Content-Type': req.headers.accept.indexOf('application/json') !== -1
221-
? 'application/json'
222-
: 'text/plain'
223-
});
218+
var _tmp = req.headers.accept.indexOf('application/json') !== -1 ? 'application/json' : 'text/plain';
219+
res.header('Content-Type', _tmp);
224220
res.json(200, result);
225221
}
226222
});

0 commit comments

Comments
 (0)