New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

express-form-post

Package Overview
Dependencies
Maintainers
1
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-form-post - npm Package Compare versions

Comparing version 1.0.14 to 1.0.15

71

index.js

@@ -40,6 +40,6 @@ "use strict";

let customFileMethod = user_options.filename;
user_options.filename = function(filename, fieldname, mimetype) {
let customName = customFileMethod(filename, fieldname, mimetype);
user_options.filename = function(originalname, fieldname, mimetype) {
let customName = customFileMethod(originalname, fieldname, mimetype);
if(customName == undefined || customName == "") {
return filename; // returning the filename that is being uploaded
return originalname; // returning the original name that is being uploaded
}

@@ -53,4 +53,4 @@ return customName;

case "":
user_options.filename = function(filename) {
return hasha(filename);
user_options.filename = function(originalname) {
return hasha(originalname);
};

@@ -81,2 +81,11 @@ break;

busboy.on("file", (fieldname, file, filename, encoding, mimetype) => {
/*
* if there is a file with the same fieldname don't attach listeners
* or initialize buffer size for files
* duplicate variable is local to each file
*/
var duplicate = false;
req.efp._data[fieldname] == undefined ? req.efp._data[fieldname] = 0 : duplicate = true;
if(!req.efp._validate || this.options.validate(fieldname, mimetype) == false) {

@@ -91,3 +100,4 @@ req.efp._validate == true ? (

// user may use filename function but incorrectly return nothing. no warning supplied. defaults to hash
let save_filename = this.options.filename(filename, fieldname, mimetype) || hasha(filename);
let originalname = filename; // added for clarity on naming conventions
let save_filename = this.options.filename(originalname, fieldname, mimetype) || hasha(filename);
save_filename.includes("/") ? (

@@ -111,6 +121,5 @@ this.options.directory = path.join(this.options.directory, save_filename, ".."),

const file_contents = storeMethod(uploadInfo, req, this.finished, this.handleError);
file.on("data", (data) => {
if(!req.efp._finished) {
!req.efp._data[fieldname] ? req.efp._data[fieldname] = data.length : req.efp._data[fieldname] += data.length;
if(!req.efp._finished && !duplicate) {
req.efp._data[fieldname] += data.length;
file_contents.write(data);

@@ -120,10 +129,12 @@ }

file.on("limit", () => {
this.handleError(new Error("File limit reached on file"));
!duplicate ? this.handleError(new Error("File limit reached on file")) : "";
});
file.on("end", () => {
if(duplicate) return;
if(this.options.minfileSize > req.efp._data[fieldname]) {
this.handleError(new Error("Uploaded file was smaller than minfileSize"));
}
if (req.efp._data[fieldname] && !file.truncated && !req.efp._finished) {
req._files++; // amount of files that were sent to store
if (req.efp._data[fieldname] > 0 && !file.truncated && !req.efp._finished) {
// If the file wasn't empty, truncated or efp has finished - send to store
file_contents.end();

@@ -140,6 +151,4 @@ }

req.efp.busboy._finished = true;
if(req._files == 0) {
// no file was uploaded
return this.finished();
}
// will only do something if all files were saved in the store
return this.finished();
});

@@ -158,7 +167,6 @@ };

*/
req.efp = { _validate: true, _finished: false, _data: [], busboy: { _finished: false }};
req.efp = { _validate: true, _finished: false, _data: {}, busboy: { _finished: false }};
req.body = {};
req.files = {};
req._files = 0; // the amount of files currently in the upload process after concatenating streams
/*

@@ -177,3 +185,3 @@ * In middleware, this.finished passes on to next middleware

}
if(Object.keys(req.files).length == req._files && req.efp.busboy._finished) {
if(Object.keys(req.files).length == Object.keys(req.efp._data).length && req.efp.busboy._finished) {
// all files that were sent to the store have been uploaded and busboy is done parsing

@@ -201,3 +209,3 @@ req.efp._finished = true;

this.handleError = () => {
!req.efp._finished && req._files == 0 ? (
!req.efp._finished ? (
req.efp._finished = true,

@@ -211,11 +219,14 @@ this.next()

if(req._body) return this.finished();
let busboy = new Busboy({
headers: req.headers,
limits: {
fileSize: this.options.maxfileSize
}
});
storeInMemory.bind(this)(busboy, req);
req.pipe(busboy);
try {
var busboy = new Busboy({
headers: req.headers,
limits: {
fileSize: this.options.maxfileSize
}
});
storeInMemory.bind(this)(busboy, req);
req.pipe(busboy);
} catch(err) {
this.handleError(err);
}
} else {

@@ -222,0 +233,0 @@ return cb();

@@ -21,8 +21,8 @@ const concat = require("concat-stream");

};
s3.upload(s3params, (err, data) => {
s3.upload(s3params, (err, response) => {
if (err) {
handleError(err);
} else {
req.files[uploadInfo.fieldname] = data;
req.files[uploadInfo.fieldname].size = req.efp._data[uploadInfo.fieldname];
req.files[uploadInfo.fieldname] = response;
req.files[uploadInfo.fieldname].size = data.byteLength;
cb();

@@ -29,0 +29,0 @@ }

@@ -32,11 +32,14 @@ const concat = require("concat-stream");

writeStream.write(data, () => {
req.files[uploadInfo.fieldname] = {
path: save_path,
filename: uploadInfo.filename,
mimetype: uploadInfo.mimetype,
encoding: uploadInfo.encoding,
size: req.efp._data[uploadInfo.fieldname]
};
// decrement unique count if there's a duplicate.
req.files[uploadInfo.fieldname] ? req._files-- : (
req.files[uploadInfo.fieldname] = {
path: save_path,
filename: uploadInfo.filename,
mimetype: uploadInfo.mimetype,
encoding: uploadInfo.encoding,
size: data.byteLength
}
);
cb();
});
};
const concat = require("concat-stream");
const request = require("request");
const path = require("path");

@@ -8,3 +9,11 @@

// Upload file to google drive here from data buffer
request.post({
url: "http://localhost:5000",
multipart: [
{ body: data }
]
}, (err, httpResponse, body) => {
console.log("Received response from server:", body);
});
});
};
{
"name": "express-form-post",
"version": "1.0.14",
"version": "1.0.15",
"description": "Simple, reliable express http file and post body handler.",

@@ -35,3 +35,4 @@ "main": "index.js",

"hasha": "^3.0.0",
"mkdirp": "^0.5.1"
"mkdirp": "^0.5.1",
"request": "^2.81.0"
},

@@ -38,0 +39,0 @@ "devDependencies": {

# Express Form Post [![npm version](https://badge.fury.io/js/express-form-post.svg)](https://badge.fury.io/js/express-form-post) [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://github.com/feross/standard)
A simple solution to handling file and form submissions <br/>
Note: this is not recommended for use by applications that handle large files. This is a quick solution to any application that handle small to medium sized files.

@@ -35,6 +36,6 @@ ## Installation

maxfileSize: 10000,
filename: function(filename, fieldname, mimetype) {
return Date.now() + "-" + filename;
filename: function(originalname, fieldname, mimetype) {
return Date.now() + "-" + originalname;
},
validate: function(fieldname, filename, mimetype) {
validate: function(fieldname, originalname, mimetype) {
console.log(mimetype);

@@ -66,4 +67,4 @@ if(mimetype != "application/pdf") {

maxfileSize: 100000,
filename: function(filename, fieldname, mimetype) {
return filename;
filename: function(originalname, fieldname, mimetype) {
return originalname;
},

@@ -121,2 +122,2 @@ keys: {

* google drive
* dropbox
* dropbox
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