上海Allen
上海Allen
  • 发布:2017-09-12 19:59
  • 更新:2019-01-25 10:19
  • 阅读:3859

html5plus io模块resolveLocalFileSystemURL 异步操作的问题

分类:HTML5+

我有个方法是相册里多选图片,遍历多选的图片,判断图片的大小,如果超过500k就对图片进行压缩,但是读取图片信息的方法是异步的,导致最后我收集到图片的数组数据会丢失图片,我觉得是异步的问题导致,不知道大神们对于这种需求有什么处理方案,有没有其他获取图片大小的方法
线谢过各位帮忙的大神

function appendByGallery(){
plus.gallery.pick(function(e){
for(var i in e.files){
var p = plus.io.convertLocalFileSystemURL(e.files[i]);
//appendFile(p);
//文件对象获取,并进行大小判断
var filePath = p;
if(plus.os.name=='iOS'){
filePath = 'file://'+p;
}

            plus.io.resolveLocalFileSystemURL( filePath, function( entry ) {  
                entry.file( function(file){  
                    var fileReader = new plus.io.FileReader();  
                    //alert("getFile:" + JSON.stringify(file));  
                    //大于500kb  
                    var max_kb = 500*1024;  
                    if(file.size>max_kb){  
                        imgZip(file.fullPath);  
                    }else{  
                        appendFile(file.fullPath);  
                    };  
                } );  
            }, function ( e ) {  
                alert( "图片读取失败: " + e.message );  
            });  
        }  
    },   
    function ( e ) {  
        console.log(e);  
    },  
    {filter:"image",multiple:true});  
}  
2017-09-12 19:59 负责人:无 分享
已邀请:
上海Allen

上海Allen (作者)

相册多选图片大家都是怎么处理的

z***@163.com

z***@163.com - 解决iOS离线打包相关项目及问题

遇到同样的问题,简直了,各位都是怎么处理的?

3***@qq.com

3***@qq.com

可以使用递归函数 处理上传

该问题目前已经被锁定, 无法添加新回复