Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

multer

Package Overview
Dependencies
Maintainers
3
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

multer - npm Package Compare versions

Comparing version 1.3.1 to 1.4.0

lib/multer-error.js

4

CHANGELOG.md

@@ -6,2 +6,6 @@ # Change log

## 1.4.0 - 2018-09-26
- Feature: Make Multer errors inherit from MulterError
## 1.3.1 - 2018-06-28

@@ -8,0 +12,0 @@

5

index.js

@@ -1,2 +0,1 @@

var makeError = require('./lib/make-error')
var makeMiddleware = require('./lib/make-middleware')

@@ -6,2 +5,3 @@

var memoryStorage = require('./storage/memory')
var MulterError = require('./lib/multer-error')

@@ -41,3 +41,3 @@ function allowAll (req, file, cb) {

if ((filesLeft[file.fieldname] || 0) <= 0) {
return cb(makeError('LIMIT_UNEXPECTED_FILE', file.fieldname))
return cb(new MulterError('LIMIT_UNEXPECTED_FILE', file.fieldname))
}

@@ -106,1 +106,2 @@

module.exports.memoryStorage = memoryStorage
module.exports.MulterError = MulterError

@@ -8,3 +8,3 @@ var is = require('type-is')

var Counter = require('./counter')
var makeError = require('./make-error')
var MulterError = require('./multer-error')
var FileAppender = require('./file-appender')

@@ -80,3 +80,3 @@ var removeUploadedFiles = require('./remove-uploaded-files')

function abortWithCode (code, optionalField) {
abortWithError(makeError(code, optionalField))
abortWithError(new MulterError(code, optionalField))
}

@@ -83,0 +83,0 @@

{
"name": "multer",
"description": "Middleware for handling `multipart/form-data`.",
"version": "1.3.1",
"version": "1.4.0",
"contributors": [

@@ -22,7 +22,7 @@ "Hage Yaapa <captain@hacksparrow.com> (http://www.hacksparrow.com)",

"dependencies": {
"append-field": "^0.1.0",
"append-field": "^1.0.0",
"busboy": "^0.2.11",
"concat-stream": "^1.5.2",
"mkdirp": "^0.5.1",
"object-assign": "^3.0.0",
"object-assign": "^4.1.1",
"on-finished": "^2.3.0",

@@ -35,6 +35,6 @@ "type-is": "^1.6.4",

"form-data": "^1.0.0-rc1",
"fs-temp": "^0.1.2",
"mocha": "^2.2.5",
"fs-temp": "^1.1.2",
"mocha": "^3.5.3",
"rimraf": "^2.4.1",
"standard": "^8.2.0",
"standard": "^11.0.1",
"testdata-w3c-json-form": "^0.2.0"

@@ -41,0 +41,0 @@ },

@@ -27,2 +27,10 @@ # Multer [![Build Status](https://travis-ci.org/expressjs/multer.svg?branch=master)](https://travis-ci.org/expressjs/multer) [![NPM version](https://badge.fury.io/js/multer.svg)](https://badge.fury.io/js/multer) [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://github.com/feross/standard)

Don't forget the `enctype="multipart/form-data"` in your form.
```html
<form action="/profile" method="post" enctype="multipart/form-data">
<input type="file" name="avatar" />
</form>
```
```javascript

@@ -57,3 +65,3 @@ var express = require('express')

In case you need to handle a text-only multipart form, you can use any of the multer methods (`.single()`, `.array()`, `fields()`). Here is an example using `.array()`:
In case you need to handle a text-only multipart form, you should use the `.none()` method:

@@ -66,3 +74,3 @@ ```javascript

app.post('/profile', upload.array(), function (req, res, next) {
app.post('/profile', upload.none(), function (req, res, next) {
// req.body contains the text fields

@@ -148,3 +156,3 @@ })

Accept only text fields. If any file upload is made, error with code
"LIMIT\_UNEXPECTED\_FILE" will be issued. This is the same as doing `upload.fields([])`.
"LIMIT\_UNEXPECTED\_FILE" will be issued.

@@ -265,9 +273,10 @@ #### `.any()`

When encountering an error, multer will delegate the error to express. You can
When encountering an error, Multer will delegate the error to Express. You can
display a nice error page using [the standard express way](http://expressjs.com/guide/error-handling.html).
If you want to catch errors specifically from multer, you can call the
middleware function by yourself.
If you want to catch errors specifically from Multer, you can call the
middleware function by yourself. Also, if you want to catch only [the Multer errors](https://github.com/expressjs/multer/blob/master/lib/make-error.js#L1-L9), you can use the `MulterError` class that is attached to the `multer` object itself (e.g. `err instanceof multer.MulterError`).
```javascript
var multer = require('multer')
var upload = multer().single('avatar')

@@ -277,8 +286,9 @@

upload(req, res, function (err) {
if (err) {
// An error occurred when uploading
return
if (err instanceof multer.MulterError) {
// A Multer error occurred when uploading.
} else {
// An unknown error occurred when uploading.
}
// Everything went fine
// Everything went fine.
})

@@ -285,0 +295,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