简体   繁体   English

科尔多瓦在Windows Phone上上传图片错误

[英]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. 我正在使用Camera插件获取图像,并使用FileTransfer插件上传图像。 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: 自从我将Cordova版本更新为6.0.0以来,从Windows Phone上传图像时出现错误,但在Android 4上仍然可以正常运行。这是我的代码:

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 我不断收到错误代码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 当我登录imageURI时,出现blob:173FAAE9-680D-4FB6-A839-07230A277F4D我也尝试获取NATIVE_URI,该NATIVE_URI将我的imageURI设置为ms-appdata:///local/wp_ss_20160514_0001.png,并替换了“ appdata: “带有空字符串

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. 我最终通过将图像作为Base64字符串获取并将其发布到服务器来解决了该问题。 Nothing else worked out for me, I'm still looking for suggestions though! 我没有其他解决办法,不过我仍在寻找建议!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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