3

I've come across TJ Holowaychuk post on multipart support and how bodyParser now does what I used to to with formidable directly.I think it's quite handy, at the same time I am now confused on how to deal with: - uploading large files? Does connect-form handle everything that is needed to support uploading of files that are for example 100MB in size? - report progress during upload? I used to get the form.parse(..) event called before the change, now since it's all handled by bodyParser it's never called...

Holowaychuk says that "The downside to this is that if you wish to report upload progress, or access files and fields as the request is streamed, you will have to use formidable directly" (http://tjholowaychuk.com/). I tried to use it directly. The only way it worked for me was to put:

... app.use(app.router); before:

app.use(express.bodyParser());

So I thought that solved my problem until I wanted to use sessions which didn't work because router has to be put before bodyparser to make the upload work and: app.use(express.cookieParser()); app.use(express.session({...}) has to go after: app.use(express.bodyParser()); which throws off sessions....

So:

WHAT IS THE RIGHT WAY OF HANDLING/CONFIGURING FILE UPLOADS so that reporting progress works and sessions work all together, small and large files using this new way with connect-form?

I'm not super experienced with Node and express so if you do answer please keep that in mind if possible.

Thank you!

alessioalex
  • 62,577
  • 16
  • 155
  • 122
zumzum
  • 17,984
  • 26
  • 111
  • 172

1 Answers1

6

There's no one right answer, bodyParser() wont be for everyone. In the next version of connect we'll have multpart(), json() and urlencoded() of which bodyParser() uses all three, so if you dont want the req.files support you would just use the other two. If we can think of an elegant way to expose some of the events with multipart() / bodyParser() I'm down for that, until then you could add your own formidable middleware above bodyParser()

tjholowaychuk
  • 3,026
  • 1
  • 21
  • 6
  • makes sense. So using the bodyparser approach and giving up the progress for now is acceptable for handling large files? – zumzum Dec 14 '11 at 19:28
  • 2
    it's still perfectly acceptable, you just cant (currently) use the progress event with it this way, but at least people new to the environment can actually get it working – tjholowaychuk Dec 19 '11 at 21:50