|
楼主 |
发表于 2016-5-17 14:23:00
|
显示全部楼层
是的,我把targetWidth:800,targetHeight:800这两个参数注释掉,就能成功上传bmp文件,打开就报上面的错。
x5里 js源码:
<script type="text/javascript" charset="utf-8">
var pictureSource; //图片来源
var destinationType; //设置返回值的格式
// 等待PhoneGap连接设备
document.addEventListener("deviceready",onDeviceReady,false);
// PhoneGap准备就绪,可以使用!
function onDeviceReady() {
pictureSource=navigator.camera.PictureSourceType;
destinationType=navigator.camera.DestinationType;
}
function onLoadImageFail(message) {
alert(message);
}
function oncameraImageFail(message) {
alert(message);
}
function isCanOption(){
if(document.getElementsByName("pics").length==9){
return false;
}else
return true;
}
//本地相册上传
function loadImageLocal() {
if(isCanOption()){
//获取本地图片并显示在屏幕
navigator.camera.getPicture(onLoadImageLocalSuccess, onLoadImageFail, {mediaType : 0,//只选择图片
quality: 50,
targetWidth:800, //图片输出宽度
targetHeight:800, //图片输出高度
destinationType: destinationType.FILE_URI,
sourceType: pictureSource.PHOTOLIBRARY,
saveToPhotoAlbum:false
});
}else{
//navigator.notification.alert("最多只能发布九张图片", null, "OA知道提醒");
$.confirm({
title: 'OA知道提醒',
keyboardEnabled: true,
content: "最多只能发布九张图片",
confirmButton: '确定',
cancelButton: ' '
});
}
}
//本地图片选择成功后回调此函数
function onLoadImageLocalSuccess(imageURI) {
//if(imageURI.indexOf("media/external/images/media")>0){
uploadPic(imageURI,"photo");
//}else{
//navigator.notification.alert("只支持上传图片格式的文件哦~", null, "OA知道提醒");
//}
}
//拍照上传
function loadImageUpload() {
if(isCanOption()){
//拍照上传并显示在屏幕
navigator.camera.getPicture(onLoadImageUploadSuccess, oncameraImageFail, {quality: 50,
destinationType: destinationType.FILE_URI,
targetWidth:800, //图片输出宽度
targetHeight:800, //图片输出高度
saveToPhotoAlbum:true
});
}else{
//navigator.notification.alert("最多只能发布九张图片哦~", null, "OA知道提醒");
$.confirm({
title: 'OA知道提醒',
keyboardEnabled: true,
content: "最多只能发布九张图片",
confirmButton: '确定',
cancelButton: ' '
});
}
}
//图片拍照成功后回调此函数
function onLoadImageUploadSuccess(imageURI) {
uploadPic(imageURI,"camera");
}
function uploadPic(imageURI,type){
var options = new FileUploadOptions(); //文件参数选项
var randomNum =Math.round(Math.random() * 8999 + 1000)+(new Date()).valueOf();
options.fileKey =randomNum;//向服务端传递的file参数的parameter name
options.fileName = imageURI.substr(imageURI.lastIndexOf('/') + 1);//文件名
options.mimeType = "image/jpeg";//文件格式,默认为image/jpeg
var ft = new FileTransfer();//文件上传类
ft.onprogress = function (progressEvt) {//显示上传进度条
if (progressEvt.lengthComputable) {
navigator.notification.progressValue(Math.round(( progressEvt.loaded / progressEvt.total ) * 100));
}
}
navigator.notification.progressStart("OA知道提醒", "当前上传进度");
ft.upload(imageURI, encodeURI('http://'+window.location.host+'/questionPicUpload'), function () {
navigator.notification.progressStop();//停止进度条
navigator.notification.alert("文件上传成功!", null, "提醒");
}, null, options);
}
</script>
html页面onclick事件触发点:
<span class="anzhuo_ico" id="camera_oa" ><img src="../m/img/camera_oa.png" width="20" height="20" alt="" /></span>
<span class="anzhuo_ico" id="add_img" ><img src="../m/img/img_ico.png" width="20" height="20" alt="" /></span>
|
|