dropzone手动上传
2024-09-28 12:06:42
html:
<div class="field">
<div id="file" class="dropzone">
<div class="dz-message needsclick">
<font><font>Drop files here or click to upload.</font></font><br>
<span class="note needsclick">(Select the files you want to upload.)</span>
</div>
</div>
</div>
css:
.field{
max-width:720px;
margin: auto;
margin-top:60px;
font-size:20px;
.dropzone{
padding: 54px 54px;
.dz-message{
height:84px;
font{
line-height:28px;
}
span.note{
height:28px;
margin-top:28px;
font-size:15px;
} }
}
}
js:
Dropzone.autoDiscover = false;
var dropz = new Dropzone("#file", {
url: "uploadFile", //上传文件的接口
parallelUploads:,//并行处理多少个文件上传
uploadMultiple:true,//允许dropzone一次提交多个文件
maxFiles: ,//最大可上传的文件个数
maxFilesize: ,//MB
acceptedFiles: ".csv", //可接受的文件类型
success:function(file,data){
// console.log(this.getAcceptedFiles().length);//获取上传的文件总数
data=JSON.parse(data);
if(data.code==''){
//成功
}else{
}
},
dictMaxFilesExceeded:"文件数量过多",
dictDefaultMessage:"Drop files here or click to upload.",
dictFileTooBig:"可添加的最大文件大小为{{maxFilesize}}Mb,当前文件大小为{{filesize}}Mb ",
})
官网地址:http://www.dropzonejs.com/
dropzone需要注意的一点就是:
打开文件的那一刻,就已经开始上传了。
这样的话,就会存在一个问题,一旦我们需要上传的是多个文件,而在我们选择文件的时候漏掉了文件,那么之前的文件已经上传,现在再次添加遗漏的文件,就会再次调用接口。
这样可能我们就需要一个手动上传,即:打开文件的时候,阻止自动上传,当全部的文件已经添加成功以后,再手动按上传按钮。
html:
<div class="field">
<div id="file" class="dropzone">
<div class="dz-message needsclick">
<font><font>Drop files here or click to upload.</font></font><br>
<span class="note needsclick">(Select the files you want to upload.)</span>
</div>
</div>
</div>
<button class="button" disabled="true">上传</button>
js:
Dropzone.autoDiscover = false;
var dropz = new Dropzone("#file", {
url: "uploadFile",
// addRemoveLinks: true,
parallelUploads:,//并行处理多少个文件上传
uploadMultiple:true,//允许dropzone一次提交多个文件
maxFiles: ,//最大可上传的文件个数
maxFilesize: ,//MB
acceptedFiles: ".csv",
autoProcessQueue: false,//阻止自动上传
success:function(file,data){
// console.log(this.getAcceptedFiles().length);//获取上传的文件总数
console.log(JSON.parse(data));
data=JSON.parse(data);
if(data.code==''){
}else{
}
},
dictMaxFilesExceeded:"文件数量过多",
dictDefaultMessage:"Drop files here or click to upload.",
dictFileTooBig:"可添加的最大文件大小为{{maxFilesize}}Mb,当前文件大小为{{filesize}}Mb ", }).on('addedfile',function(file){
$( '.button' ).removeAttr('disabled');
$( '.button' ).bind( 'click', uploadHandle );
});
uploadHandle = function() {
dropz.processQueue();//开启文件上传
$( '.button' ).unbind( 'click', uploadHandle );
};
最新文章
- UP board 漫谈(1)——从Atom到UP Board
- 理解 QEMU/KVM 和 Ceph(3):存储卷挂接和设备名称
- H5图像遮罩-遁地龙卷风
- 【转】Oracle当中扫描数据的方法
- CentOS6.5 Openssl版本升级
- 《慕客网:IOS基础入门之Foundation框架初体验》学习笔记 <;五>; NSDicionary + NSMutableDictionary
- Get the log from android device
- 获取git的最后一次提交的commit id
- jQuery分析(3) - jQuery.fn.init
- iOS二进制和资源包的自检
- 寻找最大的k个数
- 推送一个已有的代码到新的 gerrit 服务器
- BOM(1)
- Unity 3D游戏开发引擎:最火的插件推荐
- 1、Jenkins的安装与简单配置
- Java获取项目根目录等其他系统属性
- vue Bus总线
- (转)Thread的中断机制(interrupt)
- (转载)Attempting to add QLayout ";"; to MainWindow ";";, which already has a layout
- 解决gitHub下载速度慢的问题
热门文章
- Error: Cannot run program ";/home/xxx/android_developer_tools/android-ndk-r8/ndk-build.cmd";: Unknown reason
- C#正则表达式匹配双引号
- Express响应方法
- 我们为什么要在C++中使用虚函数
- ROS Learning-027 (提高篇-005 A Mobile Base-03) 控制移动平台 --- Twist 消息
- ZROI2018提高day5t3
- Luogu 3466 [POI2008]KLO-Building blocks
- Python程序设计1——基础知识
- 删除GHOST中win7桌面IE删不掉的解决办法
- python基本概念——字符串