关于移动端影像配置了https之后拍出来的照片在android手机无法显示的问题

本文介绍了一个实用的JavaScript函数,该函数可以从给定的URL读取文件,并将其转换为Blob对象和DataUrl格式,适用于图片等文件的处理。通过FileReader API实现,适用于Web开发中文件预览、上传等场景。

话不多说上代码

// 函数-从url读取文件
            readFile(img){
                let vm = this;
                window.resolveLocalFileSystemURL(img.orgSrc, function(fileEntry) {
                    fileEntry.file(function (file) {
                        let reader = new FileReader();
                        let reader2 = new FileReader();
                        reader.readAsArrayBuffer(file);
                        reader2.readAsDataURL(file);

                        reader2.onloadend = function (e) {
                            console.log(e);
                            console.log(JSON.stringify(e));
                            let image = {
                                thumbnailurl:this.result,
                                // address:fileEntry.toInternalURL(), //address
                                imageId :img.imageId,
                                orgSrc:img.orgSrc, //file_path
                                imageName:img.imageName, //file_name
                            };
                            vm.imgList.push(image);
                        };


                        reader.onloadend = function (e) {
                            console.log('e.target.result',e.target.result)
                            var file = new Blob([e.target.result], {type: "image/jpeg"});
                            vm.addFile(file,img.imageId,img.imageName);
                            console.log('file',file)
                        };
                    }, function (e) {
                      console.log("fileEntry.file==="+JSON.stringify(e));
                    });
                }, function (e) {
                      console.log("resolveLocalFileSystemURL==="+JSON.stringify(e));
                });
            },

 

转载于:https://www.cnblogs.com/mingbo-zhang/p/10239253.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值