Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

最近优化了移动化图片上传的组件 #87

Open
mishe opened this issue Jan 22, 2016 · 0 comments
Open

最近优化了移动化图片上传的组件 #87

mishe opened this issue Jan 22, 2016 · 0 comments

Comments

@mishe
Copy link
Owner

mishe commented Jan 22, 2016

mobileUpload

使用File API+实现文件上传

目前支持各种格式的文件上传,图片文件支持canvas 压缩再上传服务端

文件依赖 JQUERY

参数API

  • loading:'.loading', 页面显示loading的图标selector
  • url:'', 接收数据的api接口地址
  • maxFileSize:10_1024_1024, 服务端支持的最大单文件大小
  • format:/^image/i, 支持的文件格式
  • isCompress:true, 如果是图片,可以开启客户端压缩,减少传输的数据文件
  • compressNum:0.6, 图片的压缩率,0~1 设置为1可能最终结果比未压缩还大,请慎用1.
  • beforeUpload:function(){}, 上传之前的处理,返回false可以阻止文件的上传
  • uploadStart: function(){}, 开始上传的回调
  • afterUpload: function(){}, 上传结束的回调
  • uploadProgress: function(v){} 上传的进度条
  • uploadError: function(){} 上传错误的回调
  • showThumbnail:function(){} 显示缩略图

使用范例:

<div id="proccess"></div>
压缩前:<div id="rrr1"></div>
<br>
<input type="file" multiple  id="filesss" >
<br> 压缩后:<div id="rrr2"></div>
<br>
$('#filesss').mobileUpload({
        url: '',
        beforeUpload: function () {
            console.log('beforeUpload')
        },
        uploadStart: function (file) {
            console.log('uploadStart')
            console.log('原文件大小:' + file.length);
        },
        uploadProgress: function (v) {console.log('进度' + v)},
        uploadError: function () {console.log('uploadError')},
        showThumbnail: function (file) {

            $('#rrr1').append('<img src="' + file + '">');
        },
        afterUpload: function (file, data) {
            console.log('压缩后大小:' + file.length);
            $('#rrr2').append('<img src="' + file + '">');
        }
    });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant