[英]angular file upload with nervgh/angular-file-upload
我正在從實現https://github.com/nervgh/angular-file-upload插件的角度上傳文件,我的設置是這樣的:
var vm = this,
apiUrl = appConfig.getItem('BASE_API_URL'), // base url;
vm.uploader = $scope.uploader = new FileUploader({
url: apiUrl + '/invoices/upload',
headers: {
"Content-Type": undefined
}
});
// this function is triggered by a button outside
vm.uploadAll = function () {
vm.uploader.uploadAll();
};
在HTML我
<input id="uploadFileButton"
type="file"
nv-file-select
uploader="FUCtrl.uploader"
multiple
style="display: none;"/>
// the display none is due to that this input is click triggered
// by an outside button
上傳圖片(理論上),但是Content-Type是不確定的,缺少enctype,另一方面,在服務器端,我有這個
var express = require('express'),
multer = require('multer'),
cors = require('cors');
var app = express();
app.use(cors());
app.get('*', function(){});
app.use(multer({dest:'./uploads/'}).single('photo'));
app.post('/upload', function(req, res){
console.log('hit');
console.log(req.body); // form fields
console.log(req.files); // form files
res.status(204).end();
});
app.listen(3000);
但是當我收到帖子時,我會在控制台上看到console.log(req.body); // {} console.log(req.files); //未定義
而且我無法從pdf的上傳中獲取任何數據
我想念什么?
嘿,我不知道該插件。 但是我正在使用這個https://github.com/danialfarid/ng-file-upload插件,我發現非常有用。 這是上傳文件的最簡單方法。
Upload with form submit and validations:
http://jsfiddle.net/danialfarid/maqbzv15/1118/
Upload multiple files one by one on file select:
http://jsfiddle.net/danialfarid/2vq88rfs/136/
Upload multiple files in one request on file select (html5 only):
http://jsfiddle.net/danialfarid/huhjo9jm/5/
Upload single file on file select:
http://jsfiddle.net/danialfarid/0mz6ff9o/135/
Drop and upload with $watch:
http://jsfiddle.net/danialfarid/s8kc7wg0/400/
Image Crop and Upload
最后,我發現了HTML上的解決方案
nv-file-select
應該
nv-file-select=""
並刪除
headers: {
"Content-Type": undefined
}
從上載器的配置來看,顯然那些東西並沒有很好地設置內容類型及其邊界,所以我將它們淘汰了並使其正常工作
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.