requirements:
use Nodejs to send buffer (read data returned from files) type data to the backend through http.request using post type, and the
backend is the Django framework.
question:
requestpostchunkNoderequest.write(buffer),post
Nodejs:
function doapost(data,i) {
return new Promise(function (resolve,reject) {
let contents = data
let options = {
host: "localhost",
path: "/nodepost/",
port: 8000,
method: "POST"
};
let req = http.request(options, function (res) {
console.log(""+i+"")
res.on("data", function (chunk) {
console.log(chunk);
});
res.on("end", function (d) {
resolve("end");
});
res.on("error", function (e) {
reject(e);
})
});
console.log(contents)
req.write(contents);
req.end();
contents = null;
})
}
Django:
def nodepost(request):
return HttpResponse(request.read())
run result:
you can see that request.read does not return data, and request.body of Django does not return data either. How do you get buffer data on the backend?