我正在使用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>
从Express服务的页面HTML:
$('#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(data);
}
});
// GET /my-listings/edit/[property 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/[property id]/gallery
的意思是“提交/我的列表/编辑/[物业ID]/画廊”。
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();
}
);