EDIT ----
According to @Joni's comment on the question above, this problem seems to have been fixed after the patch was sent via a transfer request .
Original answer (from OP) ----
From the study of the restler (and corresponding with the maintainer) it does not look like the restler can do what I wanted. Note. Someone made some code that would allow parts of the file as a stream, but it was not accepted into the branch, and I do not have enough experience with streams.
I solved the problem by returning to the basics. I read the RFC for multipart ( http://www.ietf.org/rfc/rfc2388.txt ) and found that there are only a few rules in building a body, mostly some extra \ r \ n and '-' in the right places.
I decided to just format the raw POST body and send it through the main node http client.
This worked:
var http = require('http'); postBody = new Buffer( '------WebKitFormBoundaryebFz3Q3NHxk7g4qY' + "\r\n" + 'Content-Disposition: form-data; name="upload"; filename="filename.csv"' + "\r\n" + 'Content-Type: text/csv' + "\r\n" + '\r\n' + 'comma,separated,values' + "\r\n" + '------WebKitFormBoundaryebFz3Q3NHxk7g4qY' + "\r\n" + 'Content-Disposition: form-data; name="returnUrl"' + "\r\n" + '\r\n' + 'http://return.url/' + "\r\n" + '------WebKitFormBoundaryebFz3Q3NHxk7g4qY--' ); var headers = { "Content-Type": "multipart/form-data; boundary=----WebKitFormBoundaryebFz3Q3NHxk7g4qY", "Content-Length": postBody.length }; //These are the post options var options = { hostname: 'myhost.com', port: 80, path: '/myPost', method: 'POST', headers: headers }; // so we can see that things look right console.log("postBody:\n" + postBody); console.log("postBody.length:\n" + postBody.length); var responseBody = ''; // set up the request and the callbacks to handle the response data var request = http.request(options, function(response) { // when we receive data, store it in a string response.on('data', function (chunk) { responseBody += chunk; }); // at end the response, run a function to do something with the response data response.on('end',function() { console.log(responseBody); }); }); // basic error function request.on('error', function(e) { console.log('problem with request: ' + e.message); }); // write our post body to the request request.write(postBody); // end the request request.end();
I hope this helps people doing multipart / form-data.
liquidki Mar 21 '13 at 21:56 2013-03-21 21:56
source share