我已尝试使用FileTransfer
将书中的图像上传到服务器,但似乎没有任何效果。
我使用Android
上传没有问题,唯一的问题是iOS
。无论我做了什么,我都会收到错误代码1。
这是我做的,首先我添加了插件,所以当我使用CLI phonegap local plugin list
检查时,我得到了这个:
[phonegap] org.apache.cordova.camera
[phonegap] org.apache.cordova.file
[phonegap] org.apache.cordova.file-transfer
[phonegap] org.apache.cordova.media
在我的代码中我使用了这个:
<button onclick='capturePhoto();' type='button'>Take Picture</button>
<img src='' id='smallImageConfirm' />
<script>
var sendAttachment;
function capturePhoto() {
$.mobile.loading( "show", { text: "Loading", textVisible: "visible", theme: "a"});
navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 30, correctOrientation: true, targetWidth: 320, destinationType: destinationType.FILE_URI, sourceType: Camera.PictureSourceType.CAMERA });
}
function onPhotoDataSuccess(imageData) {
// Get image handle
var smallImage = document.getElementById('smallImageConfirm');
// Unhide image elements
smallImage.style.display = 'block';
// Show the captured photo
// The inline CSS rules are used to resize the image
smallImage.src = "data:image/jpeg;base64," + imageData;
sendAttachment = imageData;
$.mobile.loading( "hide" );
uploadToServer();
}
function uploadToServer() {
$.mobile.loading( "show", { text: "Uploading", textVisible: "visible", theme: "a"});
$("#submit_button").attr('disabled', true);
var url = encodeURI("http://www.xxx.com/handler.php");
var params = new Object();
params.userName = "admin;
params.randName = "xxxxzzzzaaaa123";
var options = new FileUploadOptions();
options.fileKey = "file"; //depends on the api
options.fileName = sendAttachment.substr(sendAttachment.lastIndexOf('/') + 1);
options.mimeType = "image/jpeg";
options.params = params;
options.chunkedMode = true; //this is important to send both data and files
alert( sendAttachment.substr(sendAttachment.lastIndexOf('/') + 1) );
alert( sendAttachment );
//tried without these too and didn't work
sendAttachment = sendAttachment.replace("file:///", "");
sendAttachment = sendAttachment.replace("file://", "");
alert( sendAttachment );
var ft = new FileTransfer();
ft.upload(sendAttachment, url,
function win(r) {alert(r.response);},
function fail(error){alert(error.code + " " + error.source + " " + error.target);},
options);
$.mobile.loading( "hide" );
}
</script>
正如iOS
所述,我只有error.code=1
和error.source
localhost/var/mobile/Applications/0988888888332/tmp/cdv_photo_001.jpg
和error.target
var = url
以上
请帮忙