doUploadFileUrl:function(url){ //传入本地路径,将文件整理成上传格式并放入上传框
console.log(url)
var self = this;
plus.io.resolveLocalFileSystemURL(url, function(entry) {
console.log('将文件整理成上传格式',entry)
if(!entry.isFile) {
console.log("只能上传图片文件");
return false;
}
var _img_ = new Image(); //到这里就执行不下去了,报Not allowed to load local resource
console.log('new一个Image')
_img_.src = url; // 传过来的图片路径在这里用。
console.log('img对象',_img)
_img_.onload = function() {
console.log("图片加载完成");
var tmph = _img_.height;
var tmpw = _img_.width;
var isHengTu = tmpw > tmph;
var max = Math.max(tmpw, tmph);
var min = Math.min(tmpw, tmph);
var bili = min / max;
if(max > 1200) {
max = 1200;
min = Math.floor(bili * max);
};
tmph = isHengTu ? min : max;
tmpw = isHengTu ? max : min;
_img_.onload = null;//取消图片的加载完毕事件
entry.file(function(file) {
console.log('压缩前的file',file);//读取文件信息
canvasResize(file, { //图片压缩,转化
width: tmpw,
height: tmph,
crop: false,
quality: 100, //压缩质量
rotate: 0,
callback: function(data, width, height) {
console.log('压缩后的data',data)
var blob2 = self.b64toBlob(data.split(",")[1], file.type);
console.log('转化后的blob',blob2)
var myfile = new File([blob2], file.name, {type:file.type});
console.log('传入post的files',myfile)
self.post(myfile);
}
})
})
}
},function(e){//获取操作文件或目录对象失败
console.log(JSON.stringify(e))
})
},
3***@qq.com
- 发布:2018-12-11 11:09
- 更新:2018-12-11 11:09
- 阅读:1929
webview内嵌的h5页面,在这个页面内使用plus的选择图片功能获得图片路径后,如何将这个路径的图片转换成blob
分类:HTML5+
0 个回复