chjj / parted

Streaming body parser for node.js.
MIT License
63 stars 14 forks source link

Original multipart file names #6

Closed chjj closed 12 years ago

chjj commented 12 years ago

I originally tried to keep parted as simple as possible by returning the temporary paths to files with the timestamp (included for uniqueness) still in the filename. Leaving files only in req.body eventually seemed problematic, I ended up adding req.files for the middleware. After writing a few things dependent on parted, it is kind of annoying to have to remove the timestamp in order to get the original filename. I want to maybe just add a file object to the req.files object, but I worry about backward compatibility.

With this change, grabbing the original filename would entail:

var file = req.files.my_file.filename;  // original filename
var path = req.files.my_file.path;       // temporary path

A very simple object literal I have setup now looks like:

{
  path: part,
  filename: file,
  toString: function() {
    return part;
  }
}

With the toString for a kind of backward compatibility.

I would maybe add another property for file size, etc.

I don't know how many people rely on req.files being strings right now, so it's a tough call.