api - Nodejs POST request multipart/form-data -
I am trying to upload a post through a post request
According to the readme I should be able to do just that
var r = request.post ("http://posttestserver.com/post.php", requestbackback) var form = r.form () Form.append ("folder_id", "0"); Form.append ("filename", fs.createReadStream (path.join (__DERNAM, "image.png"))); Function Request Callback (error, race, body) {console.log (body); } The problem is, it does not work, I get a reply from the test server that it has left 0 post variable.
I have confirmed that this short html page server
& lt; Html & gt; & Lt; Body & gt; & Lt; Form action = "http://posttestserver.com/post.php?dir=example" method = "post" enctype = "multipart / form-data" & gt; File: & lt; Input type = "file" name = "submit" & gt; & Lt; Input type = "hidden" name = "some paragraph" value = "some value" /> & Lt; Input type = "submit" value = "send" & gt; & Lt; / Form & gt; & Lt; / Body & gt; & Lt; / Html & gt; So the question is, what am I doing wrong with the request module? Is there a better way to send with multipart / form-data node? After some more research, I decided to use it.
fs.stat ("image.jpg", function (mistake, statistics) {restler.post ("http://posttestserver.com/post.php", {multipart: true, Data: {"folder_id": "0", "filename": restler.file ("image.jpg", blank, stats.size, null, "image / jpg")}}) .on ("full", function (Data) {console.log (data);});});
Comments
Post a Comment