我正在尝试在sails v.9.x 中使用skipper 和jquery-file-uploader 将一堆文件上传到服务器。我还需要在表单和多个文件中添加另外两个字段名称。但我在让它正常工作时遇到了一些麻烦。当我登录服务器时,它说文件不存在。我能得到一些帮助吗?
这是我的前端js:
var filesList = [],
fileupload = $('#uploader'),
paramNames = [];
var button = $("button.success.start.uploadbutton");
file_upload = fileupload.fileupload({
autoUpload: false,
fileInput: $("input:file"),
}).on("fileuploadadd", function(e, data){
filesList.push(data.files[0]);
paramNames.push(e.delegatedEvent.target.name);
});
button.click(function(e){
e.preventDefault();
var data = fileupload.serialize();
var toServer = {
data: data, files:filesList, paramName: paramNames
};
console.log(file_upload.fileupload);
file_upload.fileupload('send', toServer
).success(function(result, textstatus, jqXHR){
console.log("gettting the file uploaded!");
});
});
这是服务器端:
'upload': function (req, res) {
req.file('files').upload(function (err, files) {
console.log(files);
if (err) return res.serverError(err);
return res.json({
message: files.length + ' file(s) uploaded successfully!',
files: files
});
});
和快递js:
module.exports.express = {
bodyParser: require('skipper')
}