当前位置:网站首页>webuploader文件上传 拖拽上传 进度监听 类型控制 上传结果监听控件
webuploader文件上传 拖拽上传 进度监听 类型控制 上传结果监听控件
2022-07-05 19:23:00 【-耿瑞-】
webuploader 是一款兼容性很强 且也非常好用的前端控件 vue项目中也可以使用
我们先来简单看看
大家可以先下载我上传的资源插件
https://download.csdn.net/download/weixin_45966674/85899651?spm=1001.2014.3001.5503
下载下来后我们可以看到目录如下
没错 这款插件是依赖jquery 这是个小败笔吧 不过上一代的技术 也确实基本都要依赖jq
然后我们建一个目录 建一个webuploader 将这四个文件放进里面
然后和webuploader同级目录创建页面
演示代码如下
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<!--引入WebUploader文件上传的CSS-->
<link rel="stylesheet" type="text/css" href="./webuploader/webuploader.css" media="screen" />
<script type="text/javascript" src="./webuploader/jquery-1.8.3.js"></script>
<!--引入WebUploader文件上传的JS-->
<script type="text/javascript" src="./webuploader/webuploader.js"></script>
<style> .maskUpload{
width: 300px; height: 300px; background-color: blueviolet; } </style>
</head>
<body>
<!--用来存放文件信息-->
<div class="uploader-demo">
<div class="btns">
<div id="filePicker">选择文件</div>
<button id="ctlBtn" class="mybutton" onclick="upload_imgs()">开始上传</button>
<div class = "maskUpload"></div>
</div>
</div>
<script type="text/javascript"> var uploader; $(function(){
//初始化Web Uploader,每上传一个文件都会创建一个uploader对象,同时选择多个文件时,则会创建多个uploader对象。 uploader = WebUploader.create({
// 选完文件后,是否自动上传。 auto: false, //true时,选择文件后自动上传。 // swf文件路径 swf: 'resources/widget/webuploader/Uploader.swf', // 文件接收服务端。 server: 'upload/uploadImg', // 选择文件的按钮。可选。 pick: '#filePicker', dnd: ".maskUpload", accept: {
title: '文件上传', //支持上传的文件类型 extensions: 'jpg,png,doc,xlsx', mimeTypes: '*' } }); //当文件被加入队列时触发 uploader.on('fileQueued',function (file) {
console.log(file); }); //队列中所有文件上传结束时触发 uploader.on('error', (type) => {
console.log('上传文件类型不支持时触发'); }); //文件上传中实时返回进度 uploader.on('uploadProgress', (file, percentage) => {
console.log('上传进度'+percentage); }); //文件上传成功时触发 uploader.on("uploadSuccess",function (file,response) {
console.log('上传成功'); }); //文件上传错误时触发 uploader.on('uploadError', (file, reason) => {
console.log('上传失败'); }); //队列中所有文件上传结束时触发 uploader.on('uploadFinished', (file, reason) => {
console.log('上传结束'); }); }) //上传图片 function upload_imgs() {
if (uploader){
uploader.upload(); } } </script>
</body>
</html>
然后我们点击上传 这里extensions控制文件后缀格式 我设置的格式 只支持 jpg,png,doc,xlsx
点击上传如果是对的合适 就会被加入队列 触发fileQueued 每一个文件加入队列都会触发fileQueued 我们可以定义一个数组 将fileQueued的每一次文件流都存起来展示用

然后我们上传不支持的格式 就会被uploadFinished拦截下来
我们点击上传就会触发uploadProgress 这个是这款框架我觉得最大的亮点 可以监听到上传的进度 走到多少了
执行 uploader.upload();直接上传
上传成功触发uploadSuccess
失败则执行uploadFinished
当然还有一个亮点就是拖拽上传
dnd属性控制 里面对应的就是css选择器 选择拖拽到哪块元素上触发上传
我们这里设置了 class 为 maskUpload 的div
我们将文件从电脑直接拖拽到界面上就会触发添加到队列中 也是非常的好用
但这个工具需要后台配合 server控制上传的服务端口 swf设置上传的接口名称
边栏推荐
- flume系列之:拦截器过滤数据
- PG basics -- Logical Structure Management (user and permission management)
- Xaas trap: all things serve (possible) is not what it really needs
- The relationship between temperature measurement and imaging accuracy of ifd-x micro infrared imager (module)
- Fundamentals of shell programming (Chapter 9: loop)
- What does software testing do? What are the requirements for learning?
- PHP利用ueditor实现上传图片添加水印
- Microwave radar induction module technology, real-time intelligent detection of human existence, static micro motion and static perception
- 【AI 框架基础技术】自动求导机制 (Autograd)
- C# 语言的基本语法结构
猜你喜欢

#夏日挑战赛#数据库学霸笔记,考试/面试快速复习~
PHP利用ueditor实现上传图片添加水印

Fuzor 2020软件安装包下载及安装教程

How to choose the notion productivity tools? Comparison and evaluation of notion, flowus and WOLAI

Millimeter wave radar human body sensor, intelligent perception of static presence, human presence detection application

Interviewer: what is the difference between redis expiration deletion strategy and memory obsolescence strategy?

The basic grammatical structure of C language

使用easyexcel模板导出的两个坑(Map空数据列错乱和不支持嵌套对象)

What do software test engineers do? How about the prospect of treatment?

XaaS 陷阱:万物皆服务(可能)并不是IT真正需要的东西
随机推荐
完爆面试官,一线互联网企业高级Android工程师面试题大全
How to realize the Online timer and offline timer in the game
XaaS 陷阱:万物皆服务(可能)并不是IT真正需要的东西
司空见惯 - 英雄扫雷鼠
Realizing deep learning framework from zero -- LSTM from theory to practice [practice]
四万字长文说operator new & operator delete
Microwave radar induction module technology, real-time intelligent detection of human existence, static micro motion and static perception
The basic grammatical structure of C language
Android interview, Android audio and video development
MMO项目学习一:预热
Fuzor 2020軟件安裝包下載及安裝教程
Debezium系列之:postgresql从偏移量加载正确的最后一次提交 LSN
C# 语言的基本语法结构
Go语言学习教程(十五)
Oracle fault handling: ora-10873:file * needs to be either taken out of backup or media recovered
How MySQL queries and modifies JSON data
Bitcoinwin (BCW)受邀参加Hanoi Traders Fair 2022
Can Leica capture the high-end market offered by Huawei for Xiaomi 12s?
【obs】libobs-winrt :CreateDispatcherQueueController
Common - Hero Minesweeper