dropzone.js - Dropzone多文件上传一次上传2个文件
问题描述
我有以下代码
HTML
<form action="{{ route('documents.store') }}" method="POST" class="kt-form kt-form--label-right">
@csrf
<div class="kt-portlet__body">
<div class="form-group">
<div class="dropzone dropzone-default dropzone-success" id="documents_upload" style="padding: 0;">
<div class="dropzone-msg dz-message needsclick">
<h3 class="dropzone-msg-title">Drop files here</h3>
</div>
</div>
</div>
</div>
</form>
Javascript
<script type="text/javascript">
$(document).ready(function() {
$('#documents_upload').dropzone({
url: "{{ route('documents.store') }}", // Set the url for your upload script location
paramName: "documents", // The name that will be used to transfer the file
maxFiles: 50,
maxFilesize: 4, // MB
addRemoveLinks: true,
acceptedFiles: "application/msword, application/vnd.ms-excel, application/pdf, image/*, application/vnd.openxmlformats-officedocument.wordprocessingml.document, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, image/*",
uploadMultiple: true,
headers: {
'X-CSRF-TOKEN': "{{ csrf_token() }}"
},
queuecomplete: function() {
// notify about successful upload
// window.location.replace("{{ route('client.documents.index') }}");
}
});
});
</script>
问题
似乎这一次上传了 2 个文件。因此,如果我想上传 8 个文件,它会发出 4 个请求,每个请求包含 2 个文件。我想一次上传,有什么简单的方法可以做到吗?这种方法会带来很多问题,因为用户可能会上传大量的文件,当一半都准备好时,他可以离开/刷新页面等,他必须搜索哪些文件已经上传,哪些文件没有。
解决方案
您需要告诉 dropzone 在您的 dropzone 选项中按您想要的数量进行并行上传。
<script type="text/javascript">
$(document).ready(function() {
$('#documents_upload').dropzone({
url: "{{ route('documents.store') }}", // Set the url for your upload script location
paramName: "documents", // The name that will be used to transfer the file
maxFiles: 50,
maxFilesize: 4, // MB
addRemoveLinks: true,
acceptedFiles: "application/msword, application/vnd.ms-excel, application/pdf, image/*, application/vnd.openxmlformats-officedocument.wordprocessingml.document, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, image/*",
parallelUploads:10,
uploadMultiple: true,
headers: {
'X-CSRF-TOKEN': "{{ csrf_token() }}"
},
queuecomplete: function() {
// notify about successful upload
// window.location.replace("{{ route('client.documents.index') }}");
}
});
});
让我知道它是否有效!
推荐阅读
- c++ - 尝试运行已编译的 C++ 代码时出现分段错误 11
- python - 如何使用 matplotlib 动画向 geopandas 绘图添加颜色条
- api - 通过 gitlab api 为樱桃挑选提交的 MR
- javascript - CSS堆叠顺序,变换元素打破绝对兄弟
- javafx - 无法从 DialogPane、JavaFX 的 TextField 输入中读取文本
- linux - 找不到 SSH Shell 命令(composer、npm)
- angularjs - 错误:在 Angularjs 中加载定义时 [CKEDITOR.dialog.openDialog] 对话框图像失败
- sql - PostgreSQL:哪个索引顺序更好?
- php - 递归函数调用自身直到它返回一个值
- javascript - React 对象属性分配仅在第一次有效