Git Product home page Git Product logo

connect-multiparty's Introduction

connect-multiparty

NPM Version NPM Downloads Build Status Test Coverage

connect middleware for multiparty.

I actually recommend against using this module. It's cleaner to use the multiparty API directly.

This middleware will create temp files on your server and never clean them up. Thus you should not add this middleware to all routes; only to the ones in which you want to accept uploads. And in these endpoints, be sure to delete all temp files, even the ones that you don't use.

Usage

var multipart = require('connect-multiparty');
var multipartMiddleware = multipart();
app.post('/upload', multipartMiddleware, function(req, resp) {
  console.log(req.body, req.files);
  // don't forget to delete all req.files when done
});

If you pass options to multipart(), they are passed directly into multiparty.

License

MIT

connect-multiparty's People

Contributors

andrewrk avatar dougwilson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

connect-multiparty's Issues

Stack overflow on multipart upload with domains

Hello,

I am encountering a stack overflow exception on file uploads with connect-multiparty 1.2.1 when using domains. Version 1.1.0 did not have it.

I have traced the problem to the last versions of the qs library. This version performs a clone operation. The file object produced by node-multiparty contains a stream which in turns contains the domain which in turn contains the request and reply objects. Cloning the file object gives an infinite recursion.

I have submitted a pull request on node-multiparty (pillarjs/multiparty#85) to remove the stream from the file object (which seems not necessary).

Looking at the code of connect-multiparty, I do not understand why the parse function is called on the files object. Is there a case where this array contains query strings instead of file descriptions ?
If there is no such case, getting rid of the parsing operation would also solve the problem.

Regards

fs rename ENOENT

I had a question posted on stackoverflow, although it wasn't resolved, a quick chat on irc suggested that it is an issue of the middleware processing multipart forms, which in my case was connect-multiparty

I'll be happy to provide any more details that can help fix this issue.

Error: ENOENT, open '......' when using uploadDir

I have followed the example, and have the following code:
(built on top of generator-angular-fullstack)

var config = require('../../config/environment');
var multipart = require('connect-multiparty');
var router = express.Router();
// ...
router.post('/me/:id/upload/image', auth.isAuthenticated(), multipart({ uploadDir: './upload_image_dir' }), controller.upload_image);

On an incoming request, it gives the error:

Error: ENOENT, open 'upload_image_dir/83785-xjohos.png'
POST /api/providers/me/543695a47be1540000a4fedc/upload/image 400 20ms - 63b

If I use the default value multipart(), it works:
adds it to: path/var/folders/hc/b5hvh6gx2gzgbpvy4bygt66w0000gn/T/83985-1gqp993.png

Where am I going wrong?

req.files empty on nodejs 14

I have a feeling this might be a nodejs 14 issue, maybe related to nodejs/node#33050 not sure.

Same code works on node 12.x. On nodejs 14 req.files is just an empty object. Simple app to reproduce below.

const express = require('express')
const path = require('path')
const multi = require('connect-multiparty')
const multiMiddleware = multi();
const app = express()
const port = 3000

app.get('/', (req, res) => res.sendFile(path.resolve(__dirname, './index.html')))

app.post('/upload', multiMiddleware, function (req, res) {
    console.log('got upload', req.files);
    res.send('ok');
});

app.listen(port, () => console.log(`Example app listening at http://localhost:${port}`))

Input namespace parsing

Using Express's old bodyParser with a form that has input names of some[thing]=hello the req.body would look like:

{
  some: {
    thing: 'hello'
  }
}

however using connect-multiparty I get:

{
  'some[thing]': 'hello'
}

has anyone encountered this and found a parser to achieve the first hash?

Cheers,
Ben

Unlink file when request timed out

When I tried to upload long files and the request timed out (I'm using connect-timeout), only a part of the file was uploaded. I think adding this could solve the problem:

    form.parse(req);

    req.on('close', () => {
      if(form.bytesReceived !== form.bytesExpected) {
        form.openedFiles.forEach(({ publicFile: { path }}) => fs.unlinkSync(path))
      }
    })``` 

Revive

Since connect is going to eventually remove the multipart parser, do you want to revive this project? I would make it as simple as possible (save to file only) and direct users to use the parser directly if they enable any options like defer.

TypeError: os.tmpDir is not a function

Hello and thank you for this package. Since we upgraded to NodeJS v16.11.0, we are encountering this issue

TypeError: os.tmpDir is not a function
  aop:server:error     at new Form (......\node_modules\multiparty\index.js:55:44)
  aop:server:error     at multipart (......\node_modules\connect-multiparty\index.js:56:16)

Would it be feasible to apply my suggested change?

Resolution:
in .\multiparty\index.js

FROM

self.uploadDir = options.uploadDir || os.tmpDir();

TO

self.uploadDir = options.uploadDir || os.tmpdir();

Regards,

update multiparty to 4.1.3

please Revision:update multiparty to 4.1.3, to resolve 'DeprecationWarning: os.tmpDir() is deprecated. Use os.tmpdir() instead.'

AWS upload.

Can we talk about make a feature to upload it directly to AWS S3 instance? I think it could be really helpful for many peoples.

multiparty w/ Expressjs 4.0.0.-rc2 possibly Bugged

What works:

// in my app.js
app.use(multiparty( opts ));
restComponent( app );  //the routes are initialized

What is not working:

// inside my routes/index.js
app.post('/post', ensureAuthenticated, multiparty( opts ), Post.create);

Symptomps:
the middleware never calls next()
the middleware never recieves any event: form.on('field') (or file, error)
the middleware recieves an error if the request is aborted:

Error: Request aborted
at IncomingMessage.onReqAborted (/node_modules/multiparty/index.js:146:17)
at IncomingMessage.EventEmitter.emit (events.js:92:17)

im using express v4.0.0-rc2
with connect-multiparty 1.0.3

Uploading a file from Postman/Futter

I am trying to upload a file via Postman (also tried via flutter). In both cases I am getting an error
"Cannot read property 'path' of undefined"
When I inspect the req.file I see it is empty.

I have seen others who had this issue but did not see a resolution.

I am on 2.2.0

set maxFilesSize can't response error

I found if set

var express = require('express'),
    multipart = require('connect-multiparty'),
    multipartMiddleware = multipart({
        maxFilesSize : 2 * 1024
    })
    http = require('http');

var app = express()

app.set('port', 5000);
app.get('/', function (req, res) {
    res.send('<form method="post" enctype="multipart/form-data">'
        + '<p>Title: <input type="text" name="title" /></p>'
        + '<p>Image: <input type="file" name="image" /></p>'
        + '<p><input type="submit" value="Upload" /></p>'
        + '</form>');
});

app.post('/', multipartMiddleware, function (req, res) {
    res.send('ok');
});

app.use(function (err, req, res, next){
    console.log('handle error')
    console.error(err.stack);
    res.send(500, 'Something broke!');
})


http.createServer(app).listen(app.get('port'), function () {
    console.log('env: ' + process.env.NODE_ENV);
    console.log('Express server listening on port ' + app.get('port'));
});

if I upload more than 1 MB(but work ~40KB) size file ,It will throw err in console, but it will not send response !!

so browser will hang request !!

About article last word

First question

"If you pass options to multipart(), they are passed directly into multiparty."
Excuse me, what does this sentence mean?

image

look like my code,not use variable.What's wrong with that?

Second question

connect-multiparty & multiparty ,these two libraries,what is the difference?

File upload from android device to node server

I am trying to upload a file from an Android device using ionic 3 framework to node server. It giving the below error. Same code is working fine from iphone.

0|npm      | Dev : Error error { Error: stream ended unexpectedly
0|npm      |     at Form.<anonymous> (/home/ec2-user/application/apiserver-v2/node_modules/connect-multiparty/node_modules/multiparty/index.js:764:24)
0|npm      |     at Form.emit (events.js:187:15)
0|npm      |     at Form.EventEmitter.emit (domain.js:442:20)
0|npm      |     at finishMaybe (_stream_writable.js:654:14)
0|npm      |     at endWritable (_stream_writable.js:662:3)
0|npm      |     at Form.Writable.end (_stream_writable.js:602:5)
0|npm      |     at IncomingMessage.onend (_stream_readable.js:634:10)
0|npm      |     at Object.onceWrapper (events.js:275:13)
0|npm      |     at IncomingMessage.emit (events.js:187:15)
0|npm      |     at IncomingMessage.EventEmitter.emit (domain.js:442:20)
0|npm      |     at endReadableNT (_stream_readable.js:1091:14)
0|npm      |     at process._tickCallback (internal/process/next_tick.js:174:19) status: 400, statusCode: 400 }

stream ended unexpectedly

When i don't pass any parameter in from data it shows below error

Error: stream ended unexpectedly
at Form. (C:\xampp\htdocs\school\node_modules\multiparty\index.js:754:24)
at emitNone (events.js:91:20)
at Form.emit (events.js:185:7)
at finishMaybe (_stream_writable.js:512:14)
at endWritable (_stream_writable.js:522:3)
at Form.Writable.end (_stream_writable.js:487:5)
at IncomingMessage.onend (_stream_readable.js:511:10)
at IncomingMessage.g (events.js:292:16)
at emitNone (events.js:91:20)
at IncomingMessage.emit (events.js:185:7)

Getting Request aborted Error

Error: Request aborted
at IncomingMessage.onReqAborted (D:\ProjectName\node_modules\express\node_modules\connect\node_modules\multiparty\index.js:131:17)
at IncomingMessage.EventEmitter.emit (events.js:92:17)
at abortIncoming (http.js:1911:11)
at Socket.serverSocketCloseListener (http.js:1923:5)
at Socket.EventEmitter.emit (events.js:117:20)
at TCP.close (net.js:466:12)

Am getting this issue when am uploading files. i am not even uploading big size files. Once i get this error, its blocking the current thread.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.