手ごわいモジュールを使用してファイルをアップロードしようとしています。しかし、アップロードするファイルを複数選択すると、最初のファイルのみがアップロードされます。私はノードが初めてです。
ここに私のアップロード機能があります
exports.uploadPhotos = function(req, res) {
console.log("upload received");
var form = new formidable.IncomingForm();
form.multiples = true;
form.parse(req, function(err, fields, files) {
res.status(200, {
'content-type': 'text/plain'
});
res.end('received upload:\n\n');
res.end(util.inspect({
fields: fields,
files: files
}));
});
form.on('end', function(fields, files) {
/* Temporary location of our uploaded file */
var temp_path = this.openedFiles[0].path;
/* The file name of the uploaded file */
var file_name = this.openedFiles[0].name;
/* Location where we want to copy the uploaded file */
var new_location = 'uploads/';
fs.copy(temp_path, new_location + file_name, function(err) {
if (err) {
console.error(err);
} else {
console.log("success!");
}
});
});
};
これを呼び出すと、次のように出力されます
received upload:
{ fields: { itemPhoto: '' },
files: { upload: [ [Object], [Object] ] } }
すべてのファイルをアップロードするにはどうすればよいですか?