Coder Social home page Coder Social logo

parse-multipart's Introduction

parse-multipart

A javascript/nodejs multipart/form-data parser which operates on raw data.

note

this code is not abandoned. i just keep it as its minimum as possible.

author

My name is Cristian Salazar ([email protected]) from Santiago Chile (South America).

I'm an Amazon AWS developper focused in Serverless software development, i call it: the new age of software development.

im open to remote job:

please visit my profile on: https://www.linkedin.com/in/cristian-salazar-h

Video/Tutorial

You can Watch my video on which i expose the necesary steps to implement a Multiform/form-data parser inside a Amazon Aws ApiGateway.

Background

Sometimes you have a server listeing for data arriving to it (example: the Amazon API Gateway in AWS), this is called a "endpoint". Some website or script may send data to this endpoint. It may contain files or text, a encoded video and so on. The data is packaged in a well know format called "multipart/form-data". This data must be parsed, you must know where the data is, how many data comes to you and other aspects. This component will help you on this.

As an example, The Amazon AWS ApiGateway. It operates as a facade between the http/s client (as an exampe, the browser) and your component (your lambda function, an action script etc). The "component" is the one written by you designed to extract the uploaded files or the data contained on it and then perform operations with it (storage etc).

What means "Multipart/form-data".

The 'mutipart/form-data' is the raw data attached to a POST coming inside a Http request, it has a format and marks to let you now when it starts and when it ends, this marks are also used to separate each "part of the data" that means: the same POST may have different parts: text and/or files or video,sound etc.

First, i need to clarify this point: some people think that "multipart" means: "a POST comming several times to an endpoint" each part having a "new or the next part" of the whole data", this is wrong approach and may confuse you when trying to undestand this work. Please have it in mind. The data arrives as a whole package in the same POST, that is: if you send a file, the entire file is contained in the POST, it will have a initial mark and a finalization mark, the mark is also sent to you in the same post. In other words, The "multipart" means: in the same post you will find many parts of different data separated by a mark. It may be different files, or text, etc.

The header in the multipart/form-data has fields, this let you know about what is coming to you, the next paragraph will explain this:

Data Fields

It is important to mention that sometimes the raw data contains some fields (look at the example below this lines, "filename=.." etc). So you must deal with it and parse the "field=value;" token. Some persons wrote a very nice modifications to my code in order to handle this fields in a better approach than mine, you may find the solution here: #7.

Raw data example received in an endpoint:

The raw payload is formatted as a "multipart/form-data" will look like this one:

------WebKitFormBoundaryDtbT5UpPj83kllfw
Content-Disposition: form-data; name="uploads[]"; filename="somebinary.dat"
Content-Type: application/octet-stream

some binary data...maybe the bits of a image..
------WebKitFormBoundaryDtbT5UpPj83kllfw
Content-Disposition: form-data; name="uploads[]"; filename="sometext.txt"
Content-Type: text/plain

hello how are you
------WebKitFormBoundaryDtbT5UpPj83kllfw--

The lines above represents a raw multipart/form-data payload sent by some HTTP client via form submission containing two files. We need to extract the all files contained inside it. The multipart format allows you to send more than one file in the same payload, that's why it is called: multipart.

Usage

In the next lines you can see a implementation. In this case two key values needs to be present:

  • body, which can be:
------WebKitFormBoundaryDtbT5UpPj83kllfw
Content-Disposition: form-data; name="uploads[]"; filename="sometext.txt"
Content-Type: application/octet-stream

hello how are you
------WebKitFormBoundaryDtbT5UpPj83kllfw--
  • boundary, the string which serve as a 'separator' between parts, it normally comes to you via headers. In this case, the boundary is:
	----WebKitFormBoundaryDtbT5UpPj83kllfw

Now, having this two key values then you can implement it:

	var multipart = require('parse-multipart');
	var body = "..the multipart raw body..";
	var boundary = "----WebKitFormBoundaryDtbT5UpPj83kllfw";
	var parts = multipart.Parse(body,boundary);
	
	for(var i=0;i<parts.length;i++){
		var part = parts[i];
		// will be:
		// { filename: 'A.txt', type: 'text/plain', 
		//		data: <Buffer 41 41 41 41 42 42 42 42> }
	}

The returned data is an array of parts, each one described by a filename, a type and a data, this last one is a Buffer (see also Node Buffer).

parse-multipart's People

Contributors

christiansalazar 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

Watchers

 avatar  avatar  avatar  avatar

parse-multipart's Issues

Why is parts empty?

var multipart = require('parse-multipart');
let boundary = "abcde12345"
let body = `--abcde12345\r\nContent-Disposition: form-data; name="id"\r\nContent-Type: text/plain\r\nfoo\r\n--abcde12345--`
var parts = multipart.Parse(body, boundary);
console.log(parts);

Why is parts empty?

Parser crashes on simple form fields included in formData

While testing the parser, I noticed that sending data other than files causes the script to crash while processing each part.

so adding fields to the formData like this:

formData.append('name', product.name);
formData.append('uploadFile', file, file.name);

Would cause an error like this:

var k = str.split('=');
		^
TypeError: Cannot read property 'split' of undefined

To fix this issue, additional condition for non-file data must be included in the parser process logic.

TypeError: Cannot read property 'trim' of undefined - (Python requests library)

I get the following error when I submit a POST request using Python's requests library

Stack: TypeError: Cannot read property 'trim' of undefined
     at process (/home/nishat/project/node_modules/parse-multipart/multipart.js:38:44)
     at Object.exports.Parse (/home/nishat/project/node_modules/parse-multipart/multipart.js:87:19)

My Python code (Client side):

path = 'input.png'
files = [('photo', open(path, 'rb')),]
r = requests.post(url, files=files)

The request generated in Python at client side looks like this:

--0f178608772b425484b9b4abc0f6e281
Content-Disposition: form-data; name="photo"; filename="input.png"


--0f178608772b425484b9b4abc0f6e281--

TypeError: Cannot read property 'split' of undefined at obj (/var/task/node_modules/parse-multipart/multipart.js:28:15)

Hi.

As you requested, I re-write my issue on this board.

I use your library on AWS lambda to parse multi-part, but there is an error below.

2017-07-05T12:46:46.067Z 01141173-6180-11e7-90dc-d3dd47bfb325 TypeError: Cannot read property 'split' of undefined
at obj (/var/task/node_modules/parse-multipart/multipart.js:28:15)
at process (/var/task/node_modules/parse-multipart/multipart.js:37:14)
at Object.exports.Parse (/var/task/node_modules/parse-multipart/multipart.js:87:19)
at exports.handler (/var/task/index.js:13:27)

I just copy-and paste code with your You-tube video for AWS lambda.
https://www.youtube.com/watch?v=BrYJlR0yRnw&t=183s

My aws lambda console log of bodyBuffer is below
(var bodyBuffer = new Buffer(event['body-json'].toString(), 'base64');)

2017-07-05T12:46:46.065Z 01141173-6180-11e7-90dc-d3dd47bfb325 ------WebKitFormBoundaryueWlWZHlQiRyCHAU
Content-Disposition: form-data; name="testMessage"

test message 12356
------WebKitFormBoundaryueWlWZHlQiRyCHAU
Content-Disposition: form-data; name="testFile"; filename="123.tgz"
Content-Type: application/x-compressed

� ��\Y

I have not docker image, because I just use AWS Lambda!!

If you have any question, I'll help you.
Thank you.!!

License attribution for partial implementation in unjs/h3

Hi dear @christiansalazar. First of all, thank you so much for making and sharing this amazing library 💚 Recently, we used a fork of this repo (nachomazzara/parse-multipart-data) to support multipart data utils for unjs/h3. H3 itself is MIT licensed and your license is linked here with same attribution to "The Free Software Factory".

Please let me know if you like it to be written differently in there otherwise feel free to close issue.

Linking: nachomazzara#17

Unable to get this working.

Hi, I've tried your lib in the hope of getting my code working alongside the AWS API.
However, at this point I cannot get the demo data to work.
My code for testing with your demo data is below:

let multipart = require('parse-multipart');
let parts = multipart.Parse(multipart.DemoData(),"----WebKitFormBoundaryvef1fLxmoUdYZWXp");
console.log(parts);
for(let i=0;i<parts.length;i++){
	let part = parts[i];
	console.log(part);
	// will be:
	// { filename: 'A.txt', type: 'text/plain', 
	//		data: <Buffer 41 41 41 41 42 42 42 42> }
}

I may be overlooking something, do get back to me if I've merely forgotten something

I get an empty array

Hello,

When I pass this for example:

Content-Disposition: form-data; name="from"

[email protected]
--__X_PAW_BOUNDARY__
Content-Disposition: form-data; name="to"

[email protected]
--__X_PAW_BOUNDARY__
Content-Disposition: form-data; name="subject"

This is a test
--__X_PAW_BOUNDARY__
Content-Disposition: form-data; name="reply_to"

[email protected]
--__X_PAW_BOUNDARY__
Content-Disposition: form-data; name="html"

<p>Hello</p>
--__X_PAW_BOUNDARY__
Content-Disposition: form-data; name="text"

Hello
--__X_PAW_BOUNDARY__
Content-Disposition: form-data; name="file"; filename="Screen Shot 2018-03-25 at 12.33.00 PM.png"
Content-Type: image/png

�PNG
\u001a
\u0000\u0000\u0000
IHDR\u0000\u0000\u0000\u000f\u0000\u0000\u0000\u000b�\u0006\u0000\u0000\u0000�G�\\u0

I get back an empty array, any idea what could be the problem?

Parses all data as buffers, rather than selectively depending on if data is file or not.

in Parse.process(), should discriminate the parsing of form-data items depending on their content-type, i.e:

const fileContentTypes = [
  'application/pdf',
  ...
]
Object.defineProperty(parsedPart, 'type', {
  value: contentType,
  writable: true,
  enumerable: true,
  configurable: true,
})
Object.defineProperty(parsedPart, 'data', {
  value: fileContentTypes.some(c => c === contentType)
    ? Buffer.from(part.part)
    : String.fromCharCode.apply(String, part.part).replace(/\0/g,''),
  writable: true,
  enumerable: true,
  configurable: true,
})

This makes the resulting object "parts" a lot more useful to a consumer.

Boundary not being returned

Hi,

I am currently experiencing an issue with uploading a file using multipart/form-data to AWS. I've setup the API Gateway as you have it in your video and added my lambda.

It seems that the getBoundary method is not returning a boundary and when I attempt to parse into parts that its just not working. The parts array is empty.

Any ideas or suggestions on what could be happening and how to resolve it would be most appreciated.

Thanks ,
John

LAMBDA


'use strict';

const AWS = require('aws-sdk');
const multipart = require('parse-multipart');


module.exports.fileUpload = (event, context, callback) => {

  AWS.config.update({
    accessKeyId: process.env.PUBLIC_AWS_KEY,
    secretAccessKey: process.env.SECRET_AWS_KEY
  });

  try {

    let bodyBuffer = new Buffer(event['body-json'].toString(), 'base64');
    console.log('BUFFER: ', bodyBuffer.toString());

    let boundary = multipart.getBoundary(event.params.header['content-type']);
    console.log('BOUNDARY: ', boundary);

    let parts = multipart.Parse(bodyBuffer, boundary);
    console.log('PARTS: ', parts);
    console.log('PARTS LEN: ', parts.length);

    const response = {
      statusCode: 200,
      headers: {
        "Access-Control-Allow-Origin" : "*", // Required for CORS support to work
        "Access-Control-Allow-Credentials" : false // Required for cookies, authorization headers with HTTPS
      },
      body: JSON.stringify({
        message: 'File upload com1plete'
      }),
    };
    callback(null, response);

  } catch (err) {
    console.log("ERROR: ", err);
    const response = {
      statusCode: 500,
      headers: {
        "Access-Control-Allow-Origin" : "*", // Required for CORS support to work
        "Access-Control-Allow-Credentials" : false // Required for cookies, authorization headers with HTTPS
      },
      body: JSON.stringify({
        message: 'File upload ERR: ' + err.toString()
      }),
    };
    callback(response, null);
  }
  
};

The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DI0LTY0MzczODF8MjQuOTV8fHw0MjMtOTg3W10KMjAxNzExMzB8ODY1NDJ8MDAzMjJ8MDYyOHw2ODQuNTB8MjAxNzExMDF8MjAxNzExMzB8Rm9yIHNlcnZpY2VzIHJlbmRlcmVkfDV8RXwxfDB8MzAxLjV8MjAxNzAzMjF8fEUxMTB8fHxPdXQtb2ZfdG93biB0cmF2ZWx8MjQtNjQzNzM4MXwyODkuNXx8fDQyMy05ODdbXQoyMDE3MTEzMHw4NjU0MnwwMDMyMnwxNDI2fDEyNTB8MjAxNzExMDF8MjAxNzExMzB8TW9udGhseSBSZXRhaW5lcnw2fElGfDF8MTI1MC58MTI1MHwyMDE3MTAzMXx8fHx8TW9udGhseSBSZXRhaW5lciBGZWV8MjQtNjQzNzM4MXx8fHw0MjUtOTM2W10KDQotLS0tLS1XZWJLaXRGb3JtQm91bmRhcnlxaXFFTEJDSWlSUmFTWGlNLS0NCg==',
params: 
{ path: {},
querystring: {},
header: 
{ Accept: '*/*',
'accept-encoding': 'gzip, deflate, br',
'Accept-Language': 'en-US,en;q=0.8',
'CloudFront-Forwarded-Proto': 'https',
'CloudFront-Is-Desktop-Viewer': 'true',
'CloudFront-Is-Mobile-Viewer': 'false',
'CloudFront-Is-SmartTV-Viewer': 'false',
'CloudFront-Is-Tablet-Viewer': 'false',
'CloudFront-Viewer-Country': 'US',
'content-type': 'multipart/form-data',
Host: 'row9htct2d.execute-api.us-east-1.amazonaws.com',
origin: 'http://localhost:8088',
Referer: 'http://localhost:8088/fileupload',
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36',
Via: '2.0 3ca41706981cad42d8ecaabd29f88efa.cloudfront.net (CloudFront)',
'X-Amz-Cf-Id': 'n9aypJ5g7m02dROkhxA57KOXOYQAA3sQm4VkjqmxA9XTEJvO42yj2g==',
'X-Amzn-Trace-Id': 'Root=1-59cc056f-3b0fff4e2a4dcafc6dd77544',
'X-Forwarded-For': '174.55.194.210, 205.251.250.63',
'X-Forwarded-Port': '443',
'X-Forwarded-Proto': 'https' } },
'stage-variables': {},
context: 
{ 'account-id': '',
'api-id': 'row9htct2d',
'api-key': '',
'authorizer-principal-id': '',
caller: '',
'cognito-authentication-provider': '',
'cognito-authentication-type': '',
'cognito-identity-id': '',
'cognito-identity-pool-id': '',
'http-method': 'POST',
stage: 'dev',
'source-ip': '174.55.194.210',
user: '',
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36',
'user-arn': '',
'request-id': 'bed12d29-a3bf-11e7-bc09-dd4b4cd0dee2',
'resource-id': 'b70xn9',
'resource-path': '/api/fileupload' } }

Buffer not convertible to image ? (yes it can)

Once the image file arrives in the form of:
data: <Buffer 41 41 41 41 42 42 42 42 ... >
It can not be directly converted to an image file. Is there a way to transform this data payload into a readable buffer?

parse-multipart-data or parse-multipart?

The example on parse-multipart-data using a require('parse-multipart'), not parse-multipart-data. I tried both and neither work? Which one do I install and which one do I require?
Thanks,
Donnie

Returned buffer is prefixed with cr/lf ([13, 10, ...])

I guess this might be the same issue as #11, if so just close this.

At the moment I simply slice(2) the buffer if the two first values are those, but it's not a pretty solution - works as long as I'm working with known files (jpegs, etc.), but with arbitrary files things could get shaky...

Is multipart-related supposed to work?

Thanks for the package!
We use it for a flow receiving S/Mime (AS2) but now need to switch the service to AS4 which is multipart-related with one XML (SOAP) mime part and a second as compressed (gzip).

Would that work?

Improve parsing of content-type in Parse.process()

Steer away from unsafe array access via regex, i.e.:

const contentTypeRegexResult = (new RegExp(/[cC]ontent-[tT]ype:\s*(.*)/))
  .exec(part.info)
const contentType = contentTypeRegexResult
  && contentTypeRegexResult[1]
  && typeof contentTypeRegexResult[1] === 'string'
    ? contentTypeRegexResult[1].trim().replace(/[^a-z-\/]/g, '')
    : undefined

Unsafe access to headers causes exception

multipart.js L.39, there is var file = obj(header[2]);, should be var file = obj(header[2] || header[1]);

var header = part.header.split(';');
console.log(header) //  [ 'Content-Disposition: form-data', ' name="username"' ]
var file = obj(header[2]); // <-- EXCEPTION

Lack of filename results in an error

Although in almost all use cases a filename is supplied, it is not a mandatory value.
It'd also be nice if the files "name" parameter is returned.

The error from a lacking filename arg:

/home/thomas/discord_bot/node_modules/parse-multipart/multipart.js:28
                        var k = str.split('=');
                                   ^

TypeError: Cannot read property 'split' of undefined
    at obj (/home/thomas/discord_bot/node_modules/parse-multipart/multipart.js:28:15)
    at process (/home/thomas/discord_bot/node_modules/parse-multipart/multipart.js:37:14)
    at Object.exports.Parse (/home/thomas/discord_bot/node_modules/parse-multipart/multipart.js:87:19)
    at fs.readFile (/home/thomas/discord_bot/scripts/best.js:28:25)
    at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:445:3)

I hope this isn't too much trouble.

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.