我正在使用 multer、multer-azure-storage 和 blueimp-file-upload。全部来自 unpkg.com。下面是使用完成触发器的多文件上传。截至 2017 年 10 月 22 日工作。
.js 文件:
<script src="https://unpkg.com/jquery@3.2.1/dist/jquery.min.js"></script>
<script src="https://unpkg.com/blueimp-file-upload@9.19.1/js/vendor/jquery.ui.widget.js"></script>
<script src="https://unpkg.com/blueimp-file-upload@9.19.1/js/jquery.iframe-transport.js"></script>
<script src="https://unpkg.com/blueimp-file-upload@9.19.1/js/jquery.fileupload.js"></script>
页面 html,由 express 提供:
$('#fileupload').fileupload({
url: 'https://domainwhatevs/my-listings/edit/[property id]/gallery',
paramName: '_file',
dataType: 'json',
type: 'POST',
autoUpload: true,
add: function (e, data) {
console.log('uploading:', data)
data.submit();
},
done: function (e, data) {
console.log('done triggered');
console.log(data._response.result.result[0].originalname, 'uploaded at', data._response.result.result[0].url);
$.each(data.files, function (index, file) {
// console.log(file.name, 'uploaded.')
// console.log('done');
// console.log(index);
// console.log(file);
});
console.log(data);
}
});
// GET /my-listings/edit/[属性 id]/gallery
app.get(
[
'/my-listings/edit/:_id/gallery'
],
(req, res) => {
console.log('image gallery:', req.params._id);
res.render('my-listings--edit--gallery', {
_id: req.params._id,
session: req.session
});
}
);
// POST /my-listings/edit/[属性 id]/gallery
app.post(
[
'/my-listings/edit/:_id/gallery'
],
upload.array('_file'),
(req, res, next) => {
console.log(req.files);
res.setHeader('Content-Type', 'application/json');
res.send({result: req.files});
next();
}
);