freesoftwarefactory / parse-multipart

A javascript/nodejs multipart/form-data parser which operates on raw data.
MIT License
48 stars 80 forks source link

Added support for lacking content-disposition and lacking filename #3

Open tmfksoft opened 7 years ago

tmfksoft commented 7 years ago

This PR rewrites the process function. In the PR I've added support for lacking Content-Disposition as per a multipart/related request where it isn't mandatory.

Added support for lacking filename which also isn't mandatory. Feel free to use any of the code in the PR.

It should be pretty easy to expand on my code to add support for different headers. The code was tested with Amazon AWS V1 Speech Recognition.

An example payload from Amazon AWS V1: http://haste.thomas-edwards.me/usitucezad.txt

Note the lack of Content-Disposition.

One last addition, A requests entire headers object and now be supplied to getBoundary and it'll try and extract content-type. Although will work fine as it did originally.

tmfksoft commented 7 years ago

NOTICE REGARDING CHANGING THE RETURNED DATA

I've also updated the README to reflect the changes. I ended up changing the format of the files to suit following spec where "name" is used to refer to files uploaded via a HTTP Form.

The data returned is no longer an array of files and is instead an object. The object keys will be the "name" of each file. Thus, a file uploaded with the name being "avatar" you would access the file as form.avatar In the event "name" is not supplied it will default to null. If multiple files are supplied with the same name, such as during a multiple file upload an array of files will be supplied instead.

Here's an example of what to expect:

{
   avatar: {
      type: 'image/png',
      filename: 'avatar.png',
      name: 'avatar',
      data: <Buffer 00 00 00>
   }
}

If you recieve multiple avatars:

{
   avatar: [
      {
         type: 'image/png',
         filename: 'avatar.png',
         name: 'avatar',
        data: <Buffer 00 00 00>
      },
      {
         type: 'image/png',
         filename: 'avatar.png',
         name: 'avatar',
        data: <Buffer 00 00 00>
      },
   ]
}
christiansalazar commented 7 years ago

yes you're right. The process() function should be customized, will test in my side using your payload, also will check your PR soon,

thanku:)

2017-05-25 0:19 GMT-04:00 Thomas Edwards notifications@github.com:

I've also updated the README to reflect the changes. I ended up changing the format of the files to suit following spec where "name" is used to refer to files uploaded via a HTTP Form.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/freesoftwarefactory/parse-multipart/pull/3#issuecomment-303918381, or mute the thread https://github.com/notifications/unsubscribe-auth/ABk4g3-Wmf4vgc9ZFIRBYJriIpLWGUZ5ks5r9QFvgaJpZM4Nl8ff .

--

Cristian A. Salazar

Building Next Generation Apps with Serverless/Microservices, follow me: @AmazonAwsVideos

(+569) 9649-3840 | https://plus.google.com/+ChristianSalazar Santiago. Chile.

Bitbucket https://bitbucket.org/christiansalazarh/ | Github https://github.com/freesoftwarefactory | Stackoverflow http://stackoverflow.com/users/937815/christian | Google + https://plus.google.com/+ChristianSalazar | Blog http://trucosdeprogramacionmovil.blogspot.cl/ | Youtube http://www.youtube.com/c/ChristianSalazar | Npm (NodeJs) https://www.npmjs.com/~csalazar

tmfksoft commented 7 years ago

No problem :) Let me know if you have any issues

christiansalazar commented 7 years ago

Hi there :) is possible for you to paste here a sample payload exposing this case ? @tmfksoft