|
<script type="text/javascript" charset="utf-8">
// 采集操作成功完成后的回调函数
function captureSuccess(mediaFiles) {
var smallImage = document.getElementById('smallImage');
smallImage.style.display = 'block';
smallImage.src = mediaFiles;
uploadFile(mediaFiles);
}
// 采集操作出错后的回调函数
function captureError(error) {
var msg = 'An error occurred during capture: ' + error.code;
alert(msg);
}
// “Capture Image”按钮点击事件触发函数
function captureImage() {
// 启动设备的摄像头应用程
// 允许用户最多采集2个图像
navigator.camera.getPicture(captureSuccess, captureError, {quality: 50});
}
function getPhoto() {
navigator.camera.getPicture(uploadFile1,captureError, {
quality: 100,
destinationType: navigator.camera.DestinationType.FILE_URI,
sourceType: navigator.camera.PictureSourceType.SAVEDPHOTOALBUM
});
}
// 上传文件到服务器
function uploadFile1(mediaFile) {
var ft = new FileTransfer();
var file=mediaFile+".jpg";
alert(file);
ft.upload(file,encodeURI("http://soft.wyhbs.com/handler/UploadFile.ashx"),
function(result) {
alert("ok");
console.log('Upload success: ' + result.responseCode);
console.log(result.bytesSent + ' bytes sent');
},
function(error) {
alert("error");
alert('Error uploading file ' + file + ': ' + error.code);
},
{ fileName: name });
}
function uploadFile(mediaFile) {
var ft = new FileTransfer();
ft.upload(mediaFile,encodeURI("http://soft.wyhbs.com/handler/UploadFile.ashx"),
function(result) {
console.log('Upload success: ' + result.responseCode);
console.log(result.bytesSent + ' bytes sent');
},
function(error) {
console.log('Error uploading file ' + path + ': ' + error.code);
},
{ fileName: name });
}
</script>
<button>照相</button>
<button>相册</button>
现在uploadFile1 上传直接提示ERROR,不知道为什么,请大侠指点一下。谢谢
|
|