//--------------上传照片的方法
function sel(id) {
var btnArray = [{
title: "拍照"
}, {
title: "选取"
}];
plus.nativeUI.actionSheet({
title: "选择照片",
cancel: "取消",
buttons: btnArray
}, function(e) {
var index = e.index;
switch(index) {
case 0:
break;
case 1:
collectImages("1", id);
break;
case 2:
collectImages("2", id);
break;
}
});
}
function collectImages(type, id) {
if("1" == type) {
getImages(id);
} else {
galleryImgs(id);
}
}
//拍照或录像
function getImages(id) {
var cmr = plus.camera.getCamera();
cmr.captureImage(function(p) {
plus.gallery.save(p);
plus.io.resolveLocalFileSystemURL(p, function(entry) {
showImgs(entry.toLocalURL(), id);
}, function(e) {
toToast("读取拍照文件错误:" e.message);
});
}, function(e) {
toToast("失败:" e.message);
}, {
filename: "_doc/camera/",
index: 1
});
}
//选取现有的
function galleryImgs(id) {
// 从相册中选择图片
plus.gallery.pick(function(path) {
showImgs(path, id);
}, function(e) {
toToast("取消选择图片");
}, {
filter: "image"
});
}
function showImgs(path, id) {
appendFiles(path, id);
}
function appendFiles(path, id) {
///本地转换成平台
var newurl = plus.io.convertLocalFileSystemURL(path);
console.log("newurl pre" newurl);
//平台转对象
plus.io.resolveLocalFileSystemURL(newurl, function(entry) {
console.log("newurl" newurl);
//对象转网络
newurl = entry.toRemoteURL();
console.log("newurl" newurl);
console.log(id);
var img = document.getElementById(id);
console.log(img);
img.crossOrigin = "Anonymous";
console.log("123");
console.log(img.crossOrigin);
var waiting = plus.nativeUI.showWaiting();
var ext = newurl.substring(newurl.lastIndexOf('.'),newurl.length);
localResize(newurl, function(ret) {
var r = JSON.parse(ret);
console.log(ret);
var key = "http://img.88lc.com//" r.key;
document.getElementById(id).setAttribute('src',key);
pictureNo ;
console.log("图片上传张数==" pictureNo);
waiting.close();
},ext);
console.log("dz" newurl);
});
}
appendFiles方法下面的plus.io.resolveLocalFileSystemURL在ios端返回编码错误 Android端没问题
0 个回复