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.15 to 1.0.16

lib/dropbox.js

43

index.js

@@ -24,3 +24,3 @@ "use strict";

// Available storage methods
if(!["disk", "aws-s3", "google-drive"].includes(user_options.store)) {
if(!["disk", "aws-s3", "dropbox"].includes(user_options.store)) {
if(user_options.store == undefined) {

@@ -72,5 +72,28 @@ user_options.store = "disk";

validate: user_options.validate,
keys: user_options.keys
api: user_options.api
};
this.storeMethod = require(path.join(__dirname, "lib", this.options.store));
// set up abi objects here so we won't have to recreate upon sending buffer to store handler
switch(this.options.store){
case "aws-s3":
const aws = require("aws-sdk");
aws.config.update({
accessKeyId: this.options.api.accessKeyId,
secretAccessKey: this.options.api.secretAccessKey,
});
this.apiObject = new aws.S3();
break;
case "dropbox":
const Dropbox = require('dropbox');
this.apiObject = new Dropbox({
accessToken: this.options.api.accessToken,
clientId: this.options.api.clientId,
selectUser: this.options.api.selectUser,
});
break;
default:
this.apiObject = {}; // apiObject does not init on disk
}
};

@@ -80,3 +103,3 @@

busboy.on("file", (fieldname, file, filename, encoding, mimetype) => {
busboy.on("file", (fieldname, file, originalname, encoding, mimetype) => {

@@ -100,4 +123,4 @@ /*

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

@@ -115,8 +138,8 @@ this.options.directory = path.join(this.options.directory, save_filename, ".."),

encoding: encoding,
keys: this.options.keys
api: this.options.api,
apiObject: this.apiObject
};
// init concat-stream
const storeMethod = require(path.join(__dirname, "lib", this.options.store));
const file_contents = storeMethod(uploadInfo, req, this.finished, this.handleError);
const file_contents = this.storeMethod(uploadInfo, req, this.finished, this.handleError);
file.on("data", (data) => {

@@ -133,2 +156,4 @@ if(!req.efp._finished && !duplicate) {

if(duplicate) return;
// check if this is an empty file. if so, delete it from the _data list as if it was never uploaded
req.efp._data[fieldname] == 0 ? delete req.efp._data[fieldname] : "";

@@ -138,3 +163,3 @@ if(this.options.minfileSize > req.efp._data[fieldname]) {

}
if (req.efp._data[fieldname] > 0 && !file.truncated && !req.efp._finished) {
if (req.efp._data[fieldname] && !file.truncated && !req.efp._finished) {
// If the file wasn't empty, truncated or efp has finished - send to store

@@ -141,0 +166,0 @@ file_contents.end();

@@ -7,19 +7,14 @@ const concat = require("concat-stream");

module.exports = function(uploadInfo, req, cb, handleError) {
aws.config.update({
accessKeyId: uploadInfo.keys.accessKeyId,
secretAccessKey: uploadInfo.keys.secretAccessKey,
});
const s3 = new aws.S3();
let save_path = path.join(uploadInfo.directory, uploadInfo.filename);
return concat((data) => {
let s3params = {
Bucket: uploadInfo.keys.bucketName,
Bucket: uploadInfo.api.bucketName,
Key: save_path,
ACL: uploadInfo.keys.ACL,
ACL: uploadInfo.api.ACL,
Body: data,
ContentType: uploadInfo.mimetype
};
s3.upload(s3params, (err, response) => {
uploadInfo.apiObject.upload(s3params, (err, response) => {
if (err) {
handleError(err);
handleError(new Error(err.message));
} else {

@@ -26,0 +21,0 @@ req.files[uploadInfo.fieldname] = response;

{
"name": "express-form-post",
"version": "1.0.15",
"version": "1.0.16",
"description": "Simple, reliable express http file and post body handler.",

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

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

@@ -42,2 +41,3 @@ "devDependencies": {

"dotenv": "^4.0.0",
"dropbox": "^2.5.4",
"ejs": "^2.5.6",

@@ -44,0 +44,0 @@ "eslint": "^3.19.0",

# 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.
Note: this is not recommended for use by applications that handle large files or receives a large volume of file upload requests. This is a quick solution to any application that handle small to medium sized files intended to be an abstraction for applications whose core doesn't come from file uploading.

@@ -13,3 +13,3 @@ ## Installation

The information for the file uploaded will be available in the `files` and `body` object in the `request` object. express-form-post can be dropped in as middleware or used as a function to handle file upload.
The information for the file uploaded will be available in the `files` and `body` object in the `request` object. express-form-post can be dropped in as middleware or used as a function to handle file upload. Check out the samples on the github repository for more specific usage!

@@ -54,3 +54,3 @@ ## Quick Start

## Usage with S3
## Usage with aws-s3

@@ -71,3 +71,3 @@ ```sh

},
keys: {
api: {
accessKeyId: process.env.AWS_ACCESS_KEY_ID,

@@ -85,4 +85,31 @@ secretAccessKey: process.env.secretAccessKey,

```
## As a async function
## Usage with dropbox
```sh
$ npm install dropbox --save
```
```javascript
var express = require("express");
var app = express();
var efp = require("express-form-post");
const formPost = efp({
store: "dropbox",
filename: function(originalname, fieldname, mimetype) {
return originalname;
},
api: {
accessToken: process.env.dropboxAccessToken
}
});
app.use(formPost.middleware(function(err) {
if(err) console.log(err);
console.log("Here are my files", req.files);
}));
```
## Usage as an asynchronous function
```javascript
app.post("*", (req, res, next) => {

@@ -99,9 +126,9 @@ formPost.upload(req, res, (err) => {

## API
## express-form-post API
Further API documentation will be implemented soon.
When initializing an instance of efp (express-form-post) you can provide it different options that will change the way efp handles your file uploads.
#### efp(opts)
#### express-form-post(opts)
express-form-post accepts an "optional" options parameter
express-form-post accepts an "optional" options parameter list. Keep in mind all fields are OPTIONAL. If you don't provide any, the express-form-post api will take care of that using the default options.

@@ -116,11 +143,28 @@ Key | Description | Note

`validate` | function to validate uploaded file |
`keys` | The name of the file within the `destination` | `used for cloud storage`
`api` | api configuration information (api keys) | read further documentation for specifications
## Available storage methods
* disk storage
* aws s3
* dropbox
### Will be available soon
* google drive
* dropbox
### Configuring API storage
Here are the different information you can input for each api storage. These options would go inside the api property of the options listed above.
#### aws-s3
Key | Description | Note
--- | --- | ---
`accessKeyId` | AWS access key id | This is required. You can find it here : [aws console](https://aws.amazon.com/console/)
`secretAccessKey` | secret key for aws | Optional based on your s3 settings
`bucketName` | The name of your bucket. | This is required.
`ACL` | Access control list | Privacy control. Defaults to "private"
#### dropbox
Key | Description | Note
--- | --- | ---
`accessToken` | used by Dropbox to identify your app | This is required. Check out the [docs](https://www.dropbox.com/developers)
`clientId` | Dropbox client Id | Optional
`selectUser` | Specific user in a team box | Optional

Sorry, the diff of this file is not supported yet

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