question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Hi. When using the .single function to specify that only one upload is allowed, you can make the app crash by uploading two files at the same time. The error is as follows:

fs.js:932
  binding.unlink(pathModule._makeLong(path), req);
          ^

TypeError: path must be a string
    at TypeError (native)
    at Object.fs.unlink (fs.js:932:11)
    at DiskStorage._removeFile (node_modules/multer/storage/disk.js:61:6)
    at remove (node_modules/multer/lib/make-middleware.js:64:19)
    at handleFile (node_modules/multer/lib/remove-uploaded-files.js:10:5)
    at removeUploadedFiles (node_modules/multer/lib/remove-uploaded-files.js:25:3)
    at EventEmitter.<anonymous> (node_modules/multer/lib/make-middleware.js:67:9)
    at EventEmitter.g (events.js:260:16)
    at emitNone (events.js:72:20)
    at EventEmitter.emit (events.js:166:7)
    at EventEmitter.decrement (node_modules/multer/lib/counter.js:15:32)
    at node_modules/multer/lib/make-middleware.js:146:34
    at WriteStream.<anonymous> (node_modules/multer/storage/disk.js:43:9)
    at emitNone (events.js:72:20)
    at WriteStream.emit (events.js:166:7)
    at finishMaybe (_stream_writable.js:468:14)

Thanks!

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:13 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
ohmyhuskycommented, Mar 21, 2016

I’ve got the same error and I’ve found 2 ways to reproduce the error, both using .array('files', 3):

  1. if you don’t write some limits like fileSize or something like that, just multer({ dest : 'uploads' }), then you can reproduce the error by upload more than 3 files with at least 2 mime types (at least have one file which has different type with others).
  2. if you write some limits like limits:{fileSize:1048576}, then you can reproduce the error by upload more than 3 files with at least 1 file break the fileSize rule (in fact it break two rules), even all of then are the same type, you can still get this error.

I didn’t dig much into this. Sometimes it’s very wired the code works well if you upload 4 files to it(LIMIT_UNEXPECTED_FILE error will be catch by express error handler), but if you upload 5 files, then you will get this error and the program crashed.

If you output the file before fs.unlink(path, cb), there’s no ‘path’ property, I guess because it didn’t success to upload? path ? fs.unlink(path, cb) : cb() can avoid unlink undefined path, but I don’t know if there’s something more need to be done.

node: 5.9.0

“dependencies”: { “express”: “^4.13.4”, “multer”: “^1.1.0” }

OS X 10.11.3

Chrome 49

var express = require( 'express' ); var multer = require( 'multer' ); var fs = require( 'fs' ); var app = express(); var upload = multer( { dest : 'uploads', limits : { fileSize : 1048576 } } );

app.get( '/', ( req, res ) => fs.createReadStream( 'index.html' ).pipe( res ) );

app.post( '/files', upload.array( 'files', 3 ), ( req, res ) => res.end( 'uploaded' ) );

app.use( ( err, req, res, next ) => res.end( err.code + '\n' + err.stack ) );

app.listen( 8888 );

<form action="/files" method="post" enctype="multipart/form-data"> <input type="file" name="files" multiple> <input type="submit"> </form>

0reactions
JonathanOkzcommented, Feb 14, 2016

Hi, I had the same error with multer@1.1.0 :

fs.js:975
  binding.unlink(pathModule._makeLong(path), req);
          ^

TypeError: path must be a string
    at TypeError (native)
    at Object.fs.unlink (fs.js:975:11)
    at DiskStorage._removeFile (/home/server/server/node_modules/multer/storage/disk.js:61:6)
    at remove (/home/server/server/node_modules/multer/lib/make-middleware.js:64:19)
    at handleFile (/home/server/server/node_modules/multer/lib/remove-uploaded-files.js:10:5)
    at removeUploadedFiles (/home/server/server/node_modules/multer/lib/remove-uploaded-files.js:25:3)
    at EventEmitter.<anonymous> (/home/server/server/node_modules/multer/lib/make-middleware.js:67:9)
    at EventEmitter.g (events.js:260:16)
    at emitNone (events.js:72:20)
    at EventEmitter.emit (events.js:166:7)
    at EventEmitter.decrement (/home/server/server/node_modules/multer/lib/counter.js:15:32)
    at /home/server/server/node_modules/multer/lib/make-middleware.js:146:34
    at WriteStream.<anonymous> (/home/server/server/node_modules/multer/storage/disk.js:43:9)
    at emitNone (events.js:72:20)
    at WriteStream.emit (events.js:166:7)
    at finishMaybe (_stream_writable.js:468:14)

I added : if (path) fs.unlink(path, cb) in /multer/storage/disk.js +61 as suggested @nickmitsh and the bug seems fixed

This is the good way to fix this issue ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Liability in a Single-Vehicle Accident - Nolo
Single vehicle crashes can stem from a number of causes, including driver negligence or even recklessness. The driver isn't always considered at fault...
Read more >
Single-Vehicle Accidents - HG.org
A single vehicle collision or single-vehicle accident is, as the name implies, a car collision in which only one vehicle is involved. This...
Read more >
What You Need to Know when in a Single Vehicle Accident
A single car accident involves only one vehicle that ends up colliding with something or being run off the road. These single car...
Read more >
Single Car Accident: Am I Always at Fault? - FindLaw
Fault in a single-vehicle accident, with advice for finding legal help to cover your own injuries or avoid an expensive insurance claim from ......
Read more >
What to Know About Single Car Accidents & Liability
A single-vehicle accident is any accident that causes damage to only one vehicle. Even if another driver may have contributed to the accident...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found