Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

lzwai-uploader

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lzwai-uploader

A HTML5 upload component without UI

  • 2.0.8
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

simple-uploader

一个不带UI的HTML5上传组件,为实现各种上传交互提供最大的灵活度。

依赖项:

  • jQuery 2.0+
  • simple-module(组件抽象类)

浏览器支持:IE10+、Chrome、Safari、Firefox。

###使用方法

首先在页面里引用相关脚本:

<script type="text/javascript" src="path/to/jquery.min.js"></script>
<script type="text/javascript" src="path/to/module.js"></script>
<script type="text/javascript" src="path/to/uploader.js"></script>

初始化uploader实例:

var uploader = simple.uploader({
    url: '/upload'
});

获取文件对象,然后通过uploader上传:

$('#select-file').on('change', function(e) {
    uploader.upload(this.files);
});

###API文档

####初始化选项

url

上传接口地址,必选。

params

hash对象,上传请求附带的参数,可选

fileKey

服务器端获取上传文件的key,可选,默认是'upload_file'

connectionCount

允许同时上传的文件数量,可选,默认值是3

####方法

uploader实例会暴露一些公共方法:

upload ([File Object]/[Input Element]/[File Array])

开始上传的接口,可以接受的参数有:File对象(通过input:file选择或者通过拖拽接口获取)、input:file元素或者File对象的数组。

cancel (file/fileId)

取消上传某个文件,可以接受事件传出来的file对象或者file的id。

destroy

摧毁uploader实例

readImageFile ([File Object], callback)

通过图片的File对象获取图片的base64预览图,在上传图片之前需要预览的时候非常有用。

####事件

uploader实例可以绑定一些自定义事件,例如:

uploader.on('beforeupload', function(e, file) {
  // do something before upload
});

beforeupload (e, file)

上传开始之前触发,return false可以取消上传

uploadprogress (e, file, loaded, total)

上传的过程中会触发多次,loaded是已经上传的大小,total是文件的总大小,但是是byte。

uploadsuccess (e, file, result)

上传成功的时候触发,result是服务器端返回的json响应。

uploaderror (e, file, xhr, status)

上传失败的时候触发,xhr是上传接口的XMLHttpRequest对象,status是报错信息。

uploadcomplete (e, file, responseText)

无论上传成功还是失败都会触发这个事件,responseText是响应的文本字符串。

uploadcancel (e, file)

调用uploader.cancel()方法取消上传的时候会触发这个事件

Keywords

FAQs

Package last updated on 26 Feb 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc