Socket
Socket
Sign inDemoInstall

express-fileupload

Package Overview
Dependencies
Maintainers
1
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-fileupload - npm Package Compare versions

Comparing version 1.1.1-alpha.1 to 1.1.1-alpha.2

13

lib/processMultipart.js
const Busboy = require('busboy');
const fileFactory = require('./fileFactory');
const {
getTempFilePath,
complete,
cleanupStream,
tempFileHandler
} = require('./tempFileHandler');
const {tempFileHandler} = require('./tempFileHandler');
const processNested = require('./processNested');

@@ -67,4 +62,8 @@

};
const tempHandlerGen = tempFileHandler(options, fieldname, filename);
const {getTempFilePath, complete, cleanupStream} = tempHandlerGen;
const dataHandler = options.useTempFiles
? tempFileHandler(options, fieldname, filename)
? tempHandlerGen.handler
: memHandler;

@@ -71,0 +70,0 @@

const fs = require('fs');
let writeStream;
let tempFilePath;
const path = require('path');
module.exports.getTempFilePath = function() {
return tempFilePath;
};
module.exports.cleanupStream = function() {
writeStream.end();
fs.unlink(tempFilePath, function(err) {
if (err) throw err;
});
};
module.exports.complete = function(){
writeStream.end();
};
module.exports.tempFileHandler = function(options, fieldname, filename) {
const dir = __dirname + (options.tempFileDir || '/tmp/');
const dir = path.normalize(options.tempFileDir || process.cwd() + '/tmp/');

@@ -27,17 +10,32 @@ if (!fs.existsSync(dir)) {

}
tempFilePath = dir + 'tmp' + Date.now();
writeStream = fs.createWriteStream(tempFilePath);
let tempFilePath = path.join(dir, 'tmp' + Date.now());
let writeStream = fs.createWriteStream(tempFilePath);
let fileSize = 0; // eslint-disable-line
return function(data) {
writeStream.write(data);
fileSize += data.length;
if (options.debug) {
return console.log( // eslint-disable-line
`Uploaded ${data.length} bytes for `,
fieldname,
filename
);
return {
handler: function(data) {
writeStream.write(data);
fileSize += data.length;
if (options.debug) {
return console.log( // eslint-disable-line
`Uploaded ${data.length} bytes for `,
fieldname,
filename
);
}
},
getTempFilePath: function(){
return tempFilePath;
},
cleanupStream: function(){
writeStream.end();
fs.unlink(tempFilePath, function(err) {
if (err) throw err;
});
},
complete: function(){
writeStream.end();
}
};
};
{
"name": "express-fileupload",
"version": "1.1.1-alpha.1",
"version": "1.1.1-alpha.2",
"author": "Richard Girges <richardgirges@gmail.com>",

@@ -5,0 +5,0 @@ "description": "Simple express file upload middleware that wraps around Busboy",

@@ -76,3 +76,3 @@ # express-fileupload

useTempFiles | <ul><li><code>false</code>&nbsp;**(default)**</li><li><code>true</code></ul> | Will use temporary files at the specified tempDir for managing uploads rather than using buffers in memory. This avoids memory issues when uploading large files.
tempFileDir | <ul><li><code>String</code>&nbsp;**(path)**</li></ul> | Used with the <code>useTempFiles</code> option. Path to the directory where temp files will be stored during the upload process. Add trailing slash.
tempFileDir | <ul><li><code>String</code>&nbsp;**(path)**</li></ul> | Used with the <code>useTempFiles</code> option. Path to the directory where temp files will be stored during the upload process. Feel free to add trailing slash, but it is not necessary.
parseNested | <ul><li><code>false</code>&nbsp;**(default)**</li><li><code>true</code></li></ul> | By default, req.body and req.files are flattened like this: <code>{'name': 'John', 'hobbies[0]': 'Cinema', 'hobbies[1]': 'Bike'}</code><br /><br/>When this option is enabled they are parsed in order to be nested like this: <code>{'name': 'John', 'hobbies': ['Cinema', 'Bike']}</code>

@@ -79,0 +79,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc