简体   繁体   中英

Cordova upload image error on windows phone

In my application, I'm trying to upload an image chosen from gallery or taken from camera to server. I'm using Camera plugin to get the image and FileTransfer plugin to upload my image. Ever since I updated my Cordova version to 6.0.0 uploading images from my windows phone gets an error but it still works fine on Android 4. This is my code:

function capturePhoto() {
    navigator.camera.getPicture(onPhotoURISuccess, onFail, {
        quality: 50,
        destinationType: destinationType.FILE_URI,
        sourceType: pictureSource.CAMERA,
        correctOrientation: true
    });
}

function getPhoto(source) {
    navigator.camera.getPicture(onPhotoURISuccess, onFail, {
        quality: 50,
        destinationType: destinationType.FILE_URI,
        sourceType: pictureSource.PHOTOLIBRARY
    });
}

function onPhotoURISuccess(imageURI) {
    console.log(imageURI);
    var options = new FileUploadOptions();
    options.fileKey = "myfile";
    options.fileName = imageURI.substr(imageURI.lastIndexOf('/') + 1);
    options.mimeType = "image/jpeg";
    options.httpMethod = "POST";
    options.chunkedMode = false;
    var ft = new FileTransfer();
    ft.upload(imageURI, encodeURI(domainName + "/app_action/tools/upload/default.ashx?lang=fa&maximagesize=1024&minimagewidth=150&minimageheight=150&maximagewidth=700&action=addusermedia"), win, fail, options);
}

function win(r) {
    console.log(r.response);
}

function fail(error) {
    console.log(error.code);
    console.log(error.source);
    console.log(error.target);
}

I keep getting error code 1

When I log the imageURI, I get blob:173FAAE9-680D-4FB6-A839-07230A277F4D I have also tried getting the NATIVE_URI which gives my imageURI as ms-appdata:///local/wp_ss_20160514_0001.png and also replacing the "appdata:" with an empty string

Any suggestions or answer will be great

Thanks in advance

I finally solved it by getting the image as a Base64 string, and posting it to server. Nothing else worked out for me, I'm still looking for suggestions though!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM