Appgyver/Cordova: Not able to display captured image

帅比萌擦擦* 提交于 2019-12-12 06:06:07

问题


I am able to successfully grab the image from photo library as well as camera and able to sent them to server using FileTransfer plugin, for saving them. But the only piece of code that is not working for is displaying the Image :( When I alert the ImageURI, it gives me the below path:

file://storage/sdcard0/Android/data/com.apgyver.freshandroid/cache/.Pic.jpg

I am not sure if I am missing any plugin or maybe some piece of code?

function getImage() {
    // Retrieve image file location from specified source
    navigator.camera.getPicture(uploadPhoto, function(message) {
    alert('get picture failed');
},{
    quality: 50, 
    destinationType: navigator.camera.DestinationType.FILE_URI,
    sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY
}
    );

}

function uploadPhoto(imageURI) {

    //alert(imageURI); return false;
    var image = document.getElementById('myImage');
    image.src = imageURI;

    var options = new FileUploadOptions();
    options.fileKey="file";
    options.fileName=imageURI.substr(imageURI.lastIndexOf('/')+1);
    options.mimeType="image/jpeg";

    var params = new Object();
    params.value1 = "test";
    params.value2 = "param";

    options.params = params;
    options.chunkedMode = false;

    var ft = new FileTransfer();
    ft.upload(imageURI, url, win, fail, options);
}

It does assign the path to src but image cannot be displayed.

Thanks for the help.


回答1:


You must be missing the img element with id myImage which has width and height set to some value so that it is visible, and is given display: block. Your code follows strictly the code from the examples of the Camera plugin usage and since it goes correctly to the server you should have all the plugins & permissions needed.



来源:https://stackoverflow.com/questions/28125080/appgyver-cordova-not-able-to-display-captured-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!