0
對於我的英文很抱歉。我使用MEAN棧來寫我的應用程序。我找到了一些上傳圖像和角度文件上傳的模塊是我的選擇。但是當我上傳圖像時,控制檯上的百分比顯示已完成。我正在查看上傳目錄。該文件已上傳,但無法在Image Viever中讀取。使用angular-file-upload將文件上傳到節點服務器
這裏我的代碼對角:
$scope.onFileSelect = function($files) {
for (var i = 0; i < $files.length; i++) {
var file = $files[i];
$scope.upload = $upload.upload({
url: '/posts/upload/',
method: 'POST',
file: file,
}).progress(function(evt) {
console.log('percent: ' + parseInt(100.0 * evt.loaded/evt.total));
}).success(function(data, status, headers, config) {
// file is uploaded successfully
console.log(data);
});
}
};
這裏我的代碼在節點JS:
exports.upload = function(req, res) {
var data = new Buffer('');
req.on('data', function(chunk) {
data = Buffer.concat([data, chunk]);
});
req.on('end', function() {
req.rawBody = data;
fs.writeFile(config.root + path.sep + 'public/upload' + path.sep + uuid.v1(), data ,function(err){
if(err) throw err;
console.log('ok saved')
});
res.send('ok');
});
}
我想我做了什麼錯節點,但我不能找到它。請告訴我我的錯誤。
http://stackoverflow.com/questions/22877613/angular-node - 高速 - 大圖像上載問題/ 23543687#23543687 –