[英]Extract data send from Angularjs in multipart POST to Nodejs and write to file
在使用angular js作為前端從Web瀏覽器上傳文件時,我遇到了一個嚴重的問題。 單擊發送時,會將其路由到Nodejs Express服務器。 但是我無法獲取數據。
我的任務只是瀏覽和上傳表單瀏覽器,並使用node js寫入本地磁盤。
我有很多鏈接,但沒有幫助。
使用multer模塊上傳文件。
var multer = require('multer');
使用中間件。
app.use(multer({dest: “./uploads/”}));
app.post("/upload", function(req, res, next){
if (req.files) {
console.log(util.inspect(req.files));
if (req.files.myFile.size === 0) {
return next(new Error("Hey, first would you select a file?"));
}
fs.exists(req.files.myFile.path, function(exists) {
if(exists) {
res.json({success: true});
} else {
res.jend({success: false);
}
});
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.