i'm having strange problem busboy. i'm uploading file powershell using invoke-restmethod remote server written in node.js. code works without problem if use stream function. accepts binary data , writes file onto local drive without hiccup. however, gives me "missing boundary error" when use busboy. resolves issue, pass along boundary invoke-restmethod. rids of boundary error, busboy not fire file event @ all. i've been scratching head , trying figure out 2 days , solution seems elude me. same code working fine couple of weeks ago, not anymore. i'm not sure if changes has been made work environment weird.
stream code: works fine
server code
fs = require('fs'); server = restify.createserver(); server.post('/file',restify.queryparser(),uploadfile); function uploadfile(req, res, next) { var wstream = fs.createwritestream("x.jpg"); req.pipe(wstream); } powershell
$upload= invoke-restmethod -uri "http://localhost:8088/file" -method post -infile $imagepath -contenttype 'multipart/form-data' busboy code: throws missing boundary error
server code
fs = require('fs'); server = restify.createserver(); server.post('/file',restify.queryparser(),uploadfile); function uploadfile(req, res, next) { var filestream = new busboy({ headers: req.headers }); } powershell
$upload= invoke-restmethod -uri "http://localhost:8088/file" -method post -infile $imagepath -contenttype 'multipart/form-data' powershell code boundary set , modified node.js code. "on file" not called.
powershell
$begin = @" ---blockboundary--- "@ $end = @" ---blockboundary--- "@ add-content 'requestbodysavedtofile' $begin $imagedata = get-content $imagepath -raw -encoding byte add-content 'requestbodysavedtofile' $imagedata -encoding byte add-content 'requestbodysavedtofile' $end $url = "http://localhost:8088/file" $contenttype = "multipart/form-data; boundary=$begin" $upload= invoke-restmethod -uri $url1 -method post -infile "requestbodysavedtofile" -contenttype $contenttype server code
fs = require('fs'); server = restify.createserver(); server.post('/file',restify.queryparser(),uploadfile); function uploadfile(req, res, next) { var filestream = new busboy({ headers: req.headers }); req.pipe(filestream); filestream.on('file', function(fieldname, file, filename, encoding, mimetype) { console.log('file [' + fieldname + ']: filename: ' + filename + ', encoding: ' + encoding + ', mimetype: ' + mimetype); res.end(); }); } any idea causing this? appreciate input.
the reason there no file events because request data not correctly formatted according multipart/form-data (you're @ least missing appropriate headers each part).
Comments
Post a Comment