Skip to content

Commit f17b320

Browse files
committed
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.
1 parent 63521e1 commit f17b320

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

core/server/middleware/ghost-busboy.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ var BusBoy = require('busboy'),
55
crypto = require('crypto');
66

77
// ### ghostBusboy
8-
// Process multipart file streams and copies them to a memory stream to be
9-
// processed later.
8+
// Process multipart file streams
109
function ghostBusBoy(req, res, next) {
1110
var busboy,
11+
stream,
1212
tmpDir,
1313
hasError = false;
1414

@@ -37,10 +37,10 @@ function ghostBusBoy(req, res, next) {
3737
return file.emit('end');
3838
}
3939

40-
// Create an MD5 hash of original filenae
40+
// Create an MD5 hash of original filename
4141
md5.update(filename, 'utf8');
4242

43-
tmpFileName = +new Date() + md5.digest('base64');
43+
tmpFileName = (new Date()).getTime() + md5.digest('hex');
4444

4545
filePath = path.join(tmpDir, tmpFileName || 'temp.tmp');
4646

@@ -58,7 +58,18 @@ function ghostBusBoy(req, res, next) {
5858
res.send(413, { errorCode: 413, message: 'File size limit breached.' });
5959
});
6060

61-
file.pipe(fs.createWriteStream(filePath));
61+
busboy.on('error', function (error) {
62+
console.log('Error', 'Something went wrong uploading the file', error);
63+
});
64+
65+
stream = fs.createWriteStream(filePath);
66+
67+
stream.on('error', function (error) {
68+
console.log('Error', 'Something went wrong uploading the file', error);
69+
});
70+
71+
file.pipe(stream);
72+
6273
});
6374

6475
busboy.on('field', function (fieldname, val) {

0 commit comments

Comments
 (0)