Cordova 为什么捕获的图像在设备内存中为0字节,但在库中完全可见?

Cordova 为什么捕获的图像在设备内存中为0字节,但在库中完全可见?,cordova,cordova-3,Cordova,Cordova 3,我正在使用以下Cordova PhoneGap代码成功捕获图像并将其保存到内存中,在本例中,保存到Nexus 7中的DCIM/摄像头。我可以打开图库并查看在那里拍摄的图像 问题是,当我将设备插入PC并导航到文件夹时,图像在那里,但只有0字节。在Photoshop中打开它们,它们是空白的 为什么捕获的图像在设备内存中为0字节,但在库中完全可见?如何防止从PC访问时图像为0字节 function onDeviceReady() { pictureSource=navigato

我正在使用以下Cordova PhoneGap代码成功捕获图像并将其保存到内存中,在本例中,保存到Nexus 7中的DCIM/摄像头。我可以打开图库并查看在那里拍摄的图像

问题是,当我将设备插入PC并导航到文件夹时,图像在那里,但只有0字节。在Photoshop中打开它们,它们是空白的

为什么捕获的图像在设备内存中为0字节,但在库中完全可见?如何防止从PC访问时图像为0字节

    function onDeviceReady() {
        pictureSource=navigator.camera.PictureSourceType;
        destinationType=navigator.camera.DestinationType;
    }
// SHOOT PHOTO

// STEP 2. Show thumbnail
    function onPhotoFileSuccess(imageData) {
      console.log(JSON.stringify(imageData));
      var smallImage = document.getElementById('smallImage');
      smallImage.style.display = 'block';
      smallImage.src = imageData;
    }
// STEP 1. Capture photo.
    function capturePhotoWithFile() {
        navigator.camera.getPicture(onPhotoFileSuccess, onFail, { quality: 90, destinationType: Camera.DestinationType.FILE_URI,
          sourceType : Camera.PictureSourceType.CAMERA, 
          allowEdit : true,
          encodingType: Camera.EncodingType.JPEG,
       //   targetWidth: 200,
       //   targetHeight: 200,
          popoverOptions: CameraPopoverOptions,
          saveToPhotoAlbum: true  // saves photo to internal memory, viewed in Gallery
          });
    }
我的开发环境

最新Mac Mini上的Mac OS X 10.9.1

Cordova CLI 3.4.0

对于Android 4.3、4.4 v19

在设备中测试:Android-19、Nexus7和4.3(cordova准备/cordova编译)


不适用于PG构建;没有使用Jquery或其他JS或CSS包

请检查此JSFIDLE

我相信它会像我的回答一样帮助你回答问题。基本上,我使用FileReader并在其回调函数中获得base64(请查看示例)。然后使用AJAX post将base64字符串发布到我的Web服务

UploadImageToServer: function (imageURI) {
    app.convertFileToDataURLviaFileReader(imageURI, function (base64Img) {
        var a = base64Img;
        if (a.indexOf(",") > 0) {
            a = a.split(',')[1];
        }

        $.ajax({
            type: 'POST',
            url: 'URL to post',
            data: { data: a },
            dataType: 'xml',
            crossDomain: true,
            cache: false,
            success: function (response) {
                var status = $(response).find("string").text();
                if (status != "Failed") {
                   alert("Success!");

                }
                else {
                    alert("Status is failed!");
                }

            },
            error: function (jqXHR, textStatus, errorThrown) {

            }
        });

    });

}
现在,文件读取器函数convertFileToDataURLviaFileReader如下所示:

 convertFileToDataURLviaFileReader: function (url, callback) {
    var xhr = new XMLHttpRequest();
    xhr.responseType = 'blob';
    xhr.onload = function () {
        var reader = new FileReader();
        reader.onloadend = function () {
            callback(reader.result);
        }
        reader.readAsDataURL(xhr.response);
    };
    xhr.open('GET', url);
    xhr.send();
}

我可以使用设备的本机摄像头拍摄,并在PC上访问这些图像进行图像编辑。我现在面临着一个类似的问题,你有什么解决方案吗。如果是,请分享。谢谢