node.js - Using node and restler for multipart form-data POST -
I am able to upload the file without using any restler.file in the Data section. Now I am trying to write a very small CSV data string, which I can not find the documentation for the data function, but reading the code I thought it was correct:
restler .post ("http://posttestserver.com/post.php", {multicast: true, data: {"upload": restler.data ("people.csv", "text / csv", '384; 213; Status Update '), "Return URL": ""}}}). On ("full", function (data) {console.log (data);}); Unfortunately this is just hanging out and time will end. I tried to add EOF and other things to the third argument but I know that I am missing something that I have the data string is the exact same content that works for the file when I use restler.file. If I do not want to do it before posting then I will not have to write a CSV file.
edit ---- above According to the comments of @Jooney for the given question, this problem seems to have been corrected after correcting.
From the original answer (from OP) ---- Reseller (related to the research and related to) does not seem to mean that the vibrator I He could do that. Note: Someone has made some code which will allow a file portion as a stream, but it has not been accepted in the branch and I do not have enough experience with the stream.
The problem I solved is going back to the basics I read RFC for Multipurpose () and found that there are only a few rules in body building, mostly some extra \ r \ n and '-' the right places In.
I decided to format raw POST body only and send it through the basic node http client.
This worked:
var http = need ('http'); PostBody = new buffer ('------ WebKitarmBondaryAbafs3x3H x7G4YY' + \ r \ n "+ 'Content-Disposal: Form-Data; Name =" Upload "; filename =" filename .csv "'+" \ r \ N "+' Content Type: Text / CSV '+ \" \ r \ n "+' \ r \ n '+' Comma Separator, Value '+ \" \ r \ n "+ '------ WebKitarmBondaryAbfz3x3NHxc 7g4' +" \ r \ n "+ 'Content Dispute: Form-Data; Name =" Return URL "' + '\ r \ n" +' R \ n '+' http: //return.url/ '+ "\ r \ n" +' ------ WebkitarmbondaryAbfz3x3nhxk 7G4YY - '); Var header = {"Content-type": "Multipart / form-data; CD = ---- WebKitFormerBuffs3x3Hx7G4YY "," content-length ": postbody.lanti; // These are post options var option = {hostname: 'myhost.com', port: 80 Path: '/ myPost', Method: 'Post', Header: Header}; // So we can see that the correct Console logs ("PostBody: \ n" + PostBody) appears; Console.log ( "PostBody.length: \ n" + postBody.length); var responseBody = ''; // var request = http.request (option, function to handle set-up request and callback response data) Response) {// When we receive the data, keep it in a string reaction .on ('data', function (section) {responseBody + = chuck;}); // Finally, the reaction of the data response Run a function to do something with ('end', function () {console.log (responseBody);});}); // original error function request. ('Error', function (e) { Console.log ('problem with request:' + e.message);}); // Request a request to write to our post body (postbaw D); // request request.end terminated (); I hope this helps people who have multi-party / form-data
Comments
Post a Comment