1.html 点击事件触发方法调用cordova中的getPicture处理
_this.pictureSource=navigator.camera.PictureSourceType;
_this.destinationType=navigator.camera.DestinationType;
navigator.camera.getPicture(_this.onSuccess, _this.onFail, {
quality: cameraQuality,
sourceType:1,
destinationType: _this.destinationType.FILE_URI
});
2.拍照成功 调用onSuccess ,获取失败 调用onFail
onSuccess:function(imageData){
this.fileUpload(imageData);
},
//拍照失败调用
onFail:function(message){
showMessage('拍照失败: ' + message);
},
3.回传成功触发fileUpload
fileUpload:function(imageURI){//图片上传方法
var that = this;
//var imageURI = document.getElementById('packageCamera').src;
//此处执行文件上传的操作,上传成功后执行下面代码
var options = new FileUploadOptions(); //文件参数选项
options.fileKey = "dmsFile";//向服务端传递的file参数的parameter name
options.fileName = imageURI.substr(imageURI.lastIndexOf('/') + 1);//文件名
options.mimeType = "image/jpeg";//文件格式,默认为image/jpeg
//存放 参数
options.params = {
};
options.headers = {
Authorization: "Bearer "+getParamsStorage('Token')
}
var ft = new FileTransfer();//文件上传类
/* ft.onprogress = function (progressEvt) {//显示上传进度条
if (progressEvt.lengthComputable) {
navigator.notification.progressValue(Math.round(( progressEvt.loaded / progressEvt.total ) * 100));
}
} */
ft.upload(imageURI, actionUrl, that.callbackSuccess,that.callbackFail,options);
},
4.附件上传与图片上传 fileUpload 方法执行雷同,区别在于自己使用了另一个插件cordova-plugin-file-chooser
入口如下:
filechooser.open( {}, _this.onFileSuccess, _this.onFileFail );