0

I'm using FileTransfer plugin to download an image from a remote server.

The image is stored in "storage/emulated/0/" - using the following code:

function downloadFile(fileDownloadName){
    //console.log('downloadFile');
    window.requestFileSystem(
        LocalFileSystem.PERSISTENT,
        0,
        function(fileSystem){
            //console.log('onRequestFileSystemSuccess');
            fileSystem.root.getFile(
                'dummy.html',
                {create: true, exclusive: false},
                function(fileEntry){
                    //console.log('onGetFileSuccess!');
                    var path = fileEntry.toURI().replace('dummy.html', '');
                    var fileTransfer = new FileTransfer();
                    fileEntry.remove();

                    fileTransfer.download(
                        'https://www.myserver.com/imagens/' + fileDownloadName,
                        path + fileDownloadName,
                        function(file) {
                            //console.log('download complete: ' + file.toURI());
                            return path + fileDownloadName;
                        },
                        function(error) {
                            console.log('download error source ' + error.source);
                            console.log('download error target ' + error.target);
                            console.log('upload error code: ' + error.code);
                        }
                    );  
                },
                fail
            );
        },
        fail
    );
}

So, I'm pointing the path + fileDownloadName to SRC of my image, but the image does not appear.

var location = path + fileDownloadName;
window.resolveLocalFileSystemURL(location, function(oFile) {
   oFile.file(function(readyFile) {
      var reader= new FileReader();
      reader.onloadend= function(evt) {
      $(".circle-perfil").css('background-image', 'url(' + evt.target.result + ')');
   };
   reader.readAsDataURL(readyFile); 
});

Is there something wrong I'm doing? Should I have to store the image in another folder? If yes, how to do it?

acg
  • 503
  • 3
  • 11
  • 27
  • How you are pointing the path + fileDownloadName to src image ? plz share that line as well. – AAhad Dec 05 '14 at 02:46
  • If you are using img tag then try 'src' and not background-image. and did the evt.target.result returns correct path of image, have you checked in console. – AAhad Dec 05 '14 at 03:05

1 Answers1

0

If you are using img tag then set its image as:

$(".circle-perfil").css('background', 'url(' + evt.target.result + ')');

or

$(".circle-perfil").css('content', 'url(' + evt.target.result + ')');

In case of div or span

$(".circle-perfil").css('background-image', 'url(' + evt.target.result + ')');

I had set it like:

var image = document.getElementById('cameraPic');
image.src = 'path/of/image file';
AAhad
  • 2,805
  • 1
  • 25
  • 42