Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tmfksoft
Copy link

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
Copy link
Author

tmfksoft commented May 25, 2017

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
Copy link
Contributor

christiansalazar commented May 25, 2017 via email

@tmfksoft
Copy link
Author

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

@christiansalazar
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants