-1
我想通過使用POST方法如何在node.js中使用POST方法傳輸文件?
var queryString = querystring.stringify({
"category": "1",
"photo": "/home/dmitriy/image2.jpg" // HOW I CAN TO TRANSFER THIS IMAGE?
});
var options = {
hostname: 'dimonchikone.ucoz.net',
port: 80,
path: '/uapi/photo',
method: method,
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': queryString.length
}
};
var req = http.request(options, function(res) {
console.log('STATUS: ' + res.statusCode);
console.log('HEADERS: ' + JSON.stringify(res.headers));
res.setEncoding('utf8');
res.on('data', function (chunk) {
console.log('BODY: ' + chunk);
});
});
req.on('error', function(e) {
console.log('problem with request: ' + e.message);
});
// write data to request body
req.write(queryString);
req.end();
將圖像傳送,但不知道如何?在php中,當我使用curl我只寫下代碼
"photo": "@/home/dmitriy/image2.jpg"
如何我可以在node.js中傳輸此文件?我想傳遞的圖像,然後獲得使用PHP $ _FILE