mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
ghost-busboy improvements
- use hex instead of base64 as this can cause errors when trying to reopen the file due to characters like '/' appearing - added basic console log to errors.
This commit is contained in:
parent
63521e1ce8
commit
f17b320a7b
1 changed files with 16 additions and 5 deletions
|
@ -5,10 +5,10 @@ var BusBoy = require('busboy'),
|
||||||
crypto = require('crypto');
|
crypto = require('crypto');
|
||||||
|
|
||||||
// ### ghostBusboy
|
// ### ghostBusboy
|
||||||
// Process multipart file streams and copies them to a memory stream to be
|
// Process multipart file streams
|
||||||
// processed later.
|
|
||||||
function ghostBusBoy(req, res, next) {
|
function ghostBusBoy(req, res, next) {
|
||||||
var busboy,
|
var busboy,
|
||||||
|
stream,
|
||||||
tmpDir,
|
tmpDir,
|
||||||
hasError = false;
|
hasError = false;
|
||||||
|
|
||||||
|
@ -37,10 +37,10 @@ function ghostBusBoy(req, res, next) {
|
||||||
return file.emit('end');
|
return file.emit('end');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create an MD5 hash of original filenae
|
// Create an MD5 hash of original filename
|
||||||
md5.update(filename, 'utf8');
|
md5.update(filename, 'utf8');
|
||||||
|
|
||||||
tmpFileName = +new Date() + md5.digest('base64');
|
tmpFileName = (new Date()).getTime() + md5.digest('hex');
|
||||||
|
|
||||||
filePath = path.join(tmpDir, tmpFileName || 'temp.tmp');
|
filePath = path.join(tmpDir, tmpFileName || 'temp.tmp');
|
||||||
|
|
||||||
|
@ -58,7 +58,18 @@ function ghostBusBoy(req, res, next) {
|
||||||
res.send(413, { errorCode: 413, message: 'File size limit breached.' });
|
res.send(413, { errorCode: 413, message: 'File size limit breached.' });
|
||||||
});
|
});
|
||||||
|
|
||||||
file.pipe(fs.createWriteStream(filePath));
|
busboy.on('error', function (error) {
|
||||||
|
console.log('Error', 'Something went wrong uploading the file', error);
|
||||||
|
});
|
||||||
|
|
||||||
|
stream = fs.createWriteStream(filePath);
|
||||||
|
|
||||||
|
stream.on('error', function (error) {
|
||||||
|
console.log('Error', 'Something went wrong uploading the file', error);
|
||||||
|
});
|
||||||
|
|
||||||
|
file.pipe(stream);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
busboy.on('field', function (fieldname, val) {
|
busboy.on('field', function (fieldname, val) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue