//相册相机选择
function ceMuiImageUpload(){
plus.nativeUI.actionSheet({cancel:"取消",buttons:[
{title:"拍照"},
{title:"从相册中选择"}
]}, function(e){//1 是拍照 2 从相册中选择
switch(e.index){
case 1:appendByCamera();break;
case 2:appendByGallery();break;
}
});
}
// 拍照添加文件
function appendByCamera(){
plus.camera.getCamera().captureImage(function(e){
plus.io.resolveLocalFileSystemURL(e, function(entry) {
var path = entry.toLocalURL();
uploadpic(path);
}, function(e) {
mui.toast("读取拍照文件错误:" + e.message);
});
});
}
// 从相册添加文件
function appendByGallery(){
plus.gallery.pick(function(path){
uploadpic(path);
});
}
//服务端接口路径
var server = http_url+'BaseUploadImg1';
// 上传文件
function uploadpic(picSrc){
var wt=plus.nativeUI.showWaiting();
var task=plus.uploader.createUpload(server,
{method:"POST"},
function(t,status){ //上传完成
console.log(t.responseText);
// var data = JSON.parse(t.responseText);
// console.log(data.message);
if(status==200){
alert("上传成功:"+t.responseText);
wt.close(); //关闭等待提示按钮
}else{
alert("上传失败:"+status);
wt.close();//关闭等待提示按钮
}
}
);
//添加其他参数
console.log(picSrc);
task.addData("filetype","IDImg");
task.addFile(picSrc,{'imgtype':".JPG"});
task.setRequestHeader('appkey','ksi329sk30ddsa8l3lpo4mcnb1axz3kj');
task.start();
}