1
具有簡單的表單,如下面的js小提琴http://jsfiddle.net/UdugW/我將一些表單數據發佈到我的node.js應用程序(基於sails.js)。這是從product
模型控制器的功能之一:表單在輸入類型=文件中未提供選定文件時提交時間
image_upload: function(req, res) {
if (req.method.toLowerCase() == 'post') {
console.log("request: " + util.inspect(req.body));
if(req.files && req.files.product_image){
fs.readFile(req.files.product_image.path, function (err, data) {
var imageName = req.files.product_image.name;
if(!imageName){
console.log("There was an error with image upload : " + util.index(req.files.product_image));
res.redirect("/product/new_product");
res.end();
} else {
var newPath = UPLOAD_PATH + imageName;
/// write file to uploads/fullsize folder
fs.writeFile(newPath, data, function (err) {
res.writeHead(200, {'content-type': 'text/plain'});
res.end();
return;
});
}
});
}
}else if (req.body) {
console.log("product_name: " + product_name);
console.log("product_price: " + product_price);
console.log("product_description: " + product_description);
res.writeHead(200, {'content-type': 'text/plain'});
res.end();
}
else{
console.log("request err");
res.writeHead(500, {'content-type': 'text/plain'});
res.end();
}
},
我時,我沒有上傳選擇圖像,然後我的POST請求超時的問題。任何想法爲什麼這可能發生?
這就是問題所在。我也遇到了其他問題。謝謝 :) – Patryk