demand:
Node.jsreadSteampostmongodb
current problem:
createReadStreamchunkNode.jspost
the code is as follows:
/**
* Created by Administrator on 2018/4/29.
*/
var fs = require("fs");
var http = require("http");
var queryString = require("querystring")
var filepath = "./mmp.txt";
var readSteam = fs.createReadStream(filepath);
readSteam.on("data",(chunk) => {
console.log(chunk);
let mydata = {"name":filepath, data: chunk};
console.log(123)
console.log(mydata);
doapost(mydata);
})
function doapost(data) {
let contents = queryString.stringify(data);
console.log("here");
console.log(contents);
let options = {
host: "localhost",
path: "/mytestpost/",
port: 8000,
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
"Content-Length": contents.length
}
};
let req = http.request(options, function (res) {
res.on("data", function (chunk) {
console.log(chunk.toString())
});
res.on("end", function (d) {
console.log("end")
});
res.on("error", function (e) {
console.log(e);
})
});
req.write(contents);
req.end();
}
the running result is as follows:
you can see that buffer data is lost at name=.%2Fmmp.txt&data=
during upload. How can you solve this problem?