我正在創建一個應用程序,它接收來自node.js中幾個客戶端的文件。爲此,我使用快遞多功能節點模塊。multer nodejs模塊onFileUploadStart file.size返回0
在下面的代碼我處理文件上傳:
app.use(multer({ dest: './uploads/',
rename: function (fieldname, filename){
return filename;
},
onFileUploadStart: function(file){
console.log("file size: " + file.size);
console.log(file.originalname + ' is starting...');
},
onFileUploadComplete: function(file){
console.log(file.fieldname + ' uploaded to ' + file.path);
done = true;
},
onFileUploadData: function(file, data){
//console.log("data being received " + data);
}
}));
但是,當我的onFileUploadStart
的file.size
進入裏面是0
一個multer文件對象具有以下屬性JSON對象所以我知道尺寸屬性存在。
fieldname - Field name specified in the form
originalname - Name of the file on the user's computer
name - Renamed file name
encoding - Encoding type of the file
mimetype - Mime type of the file
path - Location of the uploaded file
extension - Extension of the file
size - Size of the file in bytes
truncated - If the file was truncated due to size limitation
buffer - Raw data (is null unless the inMemory option is true)
爲什麼大小被返回爲0?
編輯: 儘管文件大小返回0文件的其他屬性,如file.originalname正在工作並返回正確的名稱。
EDIT2: 當我打印onFileUploadStart功能我碰到下面的屬性和相關的值裏面的文件:
{
filename: 'userFile',
originalname: 'name.png',
name: 'name.png',
encoding: '7bit',
mimetype: 'image/png',
path: 'uploads\\name.png',
extension: 'png',
size: 0,
truncated: null,
buffer: null
}
爲什麼multer節點模塊發送正確的一切,但文件的大小?
EDIT3:
request.body打印以下:
{ submit: 'upload file' }
是怪異。 我正在打印請求主體下面的代碼中:
app.post('/upload/', function(request, response){
console.log(request.body);
if (done == true){
response.end('file uploaded');
}
});
index.html文件,客戶端可以上傳文件:
<html>
<head>
</head>
<body>
<form id= "upload" enctype= "multipart/form-data" action="/upload/" method="post">
<input type="file" name="userFile" />
<input type="submit" name="submit" value="upload file" />
</form>
</body>
</html>
你能顯示你的請求正文嗎? – 2015-02-11 11:39:59
@BenDiamant新增 – JoaoFilipeClementeMartins 2015-02-11 11:44:54
哪裏?不能看到它 – 2015-02-11 11:45:58