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

formData fields support. #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions multipart.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,15 @@ exports.Parse = function(multipartBodyBuffer,boundary){
{ value: b, writable: true, enumerable: true, configurable: true })
return o;
}
var header = part.header.split(';');
var header = part.header.split(';');

if(part.fieldInfo != null && part.fieldInfo != ""){
var field = obj(header[1]);
Object.defineProperty( field , 'data' ,
{ value: part.fieldInfo, writable: true, enumerable: true, configurable: true })
return field;
}

var file = obj(header[2]);
var contentType = part.info.split(':')[1].trim();
Object.defineProperty( file , 'type' ,
Expand All @@ -47,6 +55,7 @@ exports.Parse = function(multipartBodyBuffer,boundary){
var header = '';
var info = ''; var state=0; var buffer=[];
var allParts = [];
var fieldInfo = ''; // this will hold the field info when part is not a file.

for(i=0;i<multipartBodyBuffer.length;i++){
var oneByte = multipartBodyBuffer[i];
Expand Down Expand Up @@ -74,6 +83,7 @@ exports.Parse = function(multipartBodyBuffer,boundary){
lastline='';
}else
if((3 == state) && newLineDetected){
fieldInfo = lastline; // fieldInfo is exposed in lastline on this step.
state=4;
buffer=[];
lastline='';
Expand All @@ -83,7 +93,7 @@ exports.Parse = function(multipartBodyBuffer,boundary){
if(((("--"+boundary) == lastline))){
var j = buffer.length - lastline.length;
var part = buffer.slice(0,j-1);
var p = { header : header , info : info , part : part };
var p = { header : header , info : info , part : part, fieldInfo : fieldInfo }; // adding fieldInfo to the part to process
allParts.push(process(p));
buffer = []; lastline=''; state=5; header=''; info='';
}else{
Expand Down