使用Phonegap在iOS上的上传图片上的Error.code 1

时间:2014-01-12 09:29:37

标签: ios cordova

我已尝试使用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=1error.source localhost/var/mobile/Applications/0988888888332/tmp/cdv_photo_001.jpgerror.target var = url以上

请帮忙

0 个答案:

没有答案