mishe / blog

前端碰上的问题或体会
230 stars 39 forks source link

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

Open mishe opened 8 years ago

mishe commented 8 years ago

mobileUpload

使用File API+实现文件上传

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

文件依赖 JQUERY

参数API

使用范例:

<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 + '">');
        }
    });