简体   繁体   English

对象存储在xmlhttprequest中的位置

[英]where is object stored in xmlhttprequest

Javascript: Javascript:

var test_request = new XMLHttpRequest();
test_request.open("POST","/testupload",true);
test_request.send(image.sourceFile);

Node.js express: Node.js表达:

app.post("/testupload", function(req, res){
    where is the image.sourceFile in req?
});

where is the image.sourceFile in req? image.sourceFile在要求中在哪里? req.body shows {}, how can I get the image? req.body显示{},如何获取图片?

if you want to the form data of a POST request, you should try to use body-parser middleware first. 如果要获取POST请求的表单数据,则应首先尝试使用body-parser中间件。

const express        = require('express');
const bodyParser     = require('body-parser');
const app            = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true, type: 'application/x-www-form-urlencoded' }));

now you can get form data in req.body ; 现在您可以在req.body获取表单数据;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM