javascript - Parse multipart file with Node/Express and upload to Azure Blob Storage -


i receiving multipart file via rest service call vendors api. file includes xml data , blob data 2 images. need able split , store these individual files using node/express. have seen lot posts/resources on multipart form data, needs parsing using javascript individual files can uploaded azure blob storage. suspect node/express or node module such request (https://github.com/request/request) right way go, haven't found concrete. here example of multipart file. note there not filename multipart file:

mime-version:1.0 content-type:multipart/mixed;  boundary="----=_part_4_153315749.1440434094461"  ------=_part_4_153315749.1440434094461 content-type: application/octet-stream; name=texture_1.png content-id: response-1 content-disposition: attachment; filename=texture_1.png  ‰png "blob data here"  ------=_part_4_153315749.1440434094461 content-type: application/octet-stream; name=manifest.xml content-id: response-2 content-disposition: attachment; filename=manifest.xml  <?xml version="1.0"?> <dae_root>blank_3d.dae</dae_root>  ------=_part_4_153315749.1440434094461 content-type: application/octet-stream; name=texture_3d.dae content-id: response-3 content-disposition: attachment; filename=texture_3d.dae  <xml data here... lots of xml data>  ------=_part_4_153315749.1440434094461 content-type: application/octet-stream; name=texture_0.png content-id: response-4 content-disposition: attachment; filename=texture_0.png  ‰png "blob image data" 

based on description, looks purely node.js issue instead of azure related 1 - feel free correct me if have misunderstood. in case, recommend leverage below 2 modules solve issue:

https://github.com/isaacs/multipart-js/

https://github.com/felixge/node-formidable

sample multipart-js parser below quick reference:

var multipart = require("multipart");  // parsing var parser = multipart.parser();  // in event handlers, "this" parser, , "this.part" // part that's being dealt with. parser.onpartbegin = function (part) { dosomething(part) }; parser.ondata = function (chunk) { dosomethingelse(chunk) }; parser.onend = function () { closeitup() };  // start feeding message through it. // can in 1 go, if like, or 1 byte @ time, // or in between. parser.boundary = "foo"; var chunk; while ( chunk = upstreamthing.getnextchunk() ) {   parser.write(chunk); } parser.close(); 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -