node.js - How to post a multipart form data using node to a rails backend? -


node uses code submit multipart form data:

var form = new formdata();  form.append(project.name+'.zip', fs.createreadstream("/"+project.name+'.zip')); form.submit({     host: 'http://host.mysite.dev',     path: '/api/v1/prototypes',     headers: {       'authentication': 'secret'     }   }, function(err, res) {     if(err) console.log("err: ", err)     else console.log("res: ", res)     console.log(res.statuscode);   }); 

my backend expecting request (tested postman).

------webkitformboundarywo69ve86h8vmc9ah content-disposition: form-data; name="attachment"; filename="basic.zip" content-type: application/zip   ------webkitformboundarywo69ve86h8vmc9ah-- 

instead, request looks crazy gibberish rails can't interpret. have no idea how make normal multipart form request node.

{ "attachment":{   "_overheadlength":157,   "_valuelength":0,   "_lengthretrievers":[      null   ],   "writable":false,   "readable":true,   "datasize":0,   "maxdatasize":2097152,   "pausestreams":true,   "_released":false,   "_streams":[      "----------------------------860185489573893683941879\r\ncontent-disposition: form-data; name=\"app.zip\"; filename=\"app.zip\"\r\ncontent-type: application-zip\r\n\r\n",    {         "source":{            "_readablestate":{               "objectmode":false,               "highwatermark":65536,               "buffer":[                  {                     "type":"buffer",                     "data":[                        80,                        181                     ]                  }               ],               "length":65536,               "pipes":null,               "pipescount":0,               "flowing":false,               "ended":false,               "endemitted":false,               "reading":false,               "sync":false,               "needreadable":false,               "emittedreadable":true,               "readablelistening":false,               "defaultencoding":"utf8",               "ranout":false,               "awaitdrain":0,               "readingmore":false,               "decoder":null,               "encoding":null            },            "readable":true,            "domain":null,            "_events":{             },            "_eventscount":3,            "path":"/users/guest/library/application support/foundation-apps-template/app.zip",            "fd":299,            "flags":"r",            "mode":438,            "autoclose":true         },         "datasize":0,         "maxdatasize":null,         "pausestream":true,         "_maxdatasizeexceeded":false,         "_released":false,         "_bufferedevents":[          ],         "_events":{          },         "_eventscount":1      },      null   ],   "_currentstream":null,   "_boundary":"--------------------------860185489573893683941879"  } } 

i don't know either a. parse crazy packet (which don't know how do). or b. normal multipart form submission. i've been stuck problem 3 work days , i've tried lot of things, none of have worked. i'm starting desperate figure out. i'm ready give on of , start assembling packet scratch - not sure how either though. @ point couldn't harder trying make nonsense work.


Comments

Popular posts from this blog

How to provide Authorization & Authentication using Asp.net, C#? -

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

How to use Authorization & Authentication in Asp.net, C#? -