Software Archive
Read-only legacy content
17061 Discussions

Downloading remote images to phone gallery

xkevin
New Contributor I
454 Views

Is there a sample or tutorial on how to download remote images with cordova plugins?

Here is the sample code of mine, displaying images after ajax succes. 

<div class="image-wrap">
    <div class="the-image">
       <a href="https:sample.com/uploads/Sep-23-2016/89896787889.jpg" class="fancybox" rel="gallery">
        <span class="attachment-wrap"><i class="fa fa-file-image-o" aria-hidden="true"></i> ..7889.jpg</span> 
       </a>
    </div>
            <div class="download-btn" >Download</div>
 </div>

 <div class="image-wrap">
    <div class="the-image">
       <a href="https:sample.com/uploads/Sep-22-2016/39495682191.jpg" class="fancybox" rel="gallery">
        <span class="attachment-wrap"><i class="fa fa-file-image-o" aria-hidden="true"></i> ..2191.jpg</span> 
       </a>
    </div>
            <div class="download-btn" >Download</div>
 </div>

Using the download button of each image how can I download image in phone's gallery. Andriod and IOS support. Any guide?

0 Kudos
2 Replies
Hamilton_Tenório_da_
Valued Contributor I
454 Views

I use this code:

//função para buscar logotipo do cliente no servidor e guardar no aparelho
function funBaixaLogotipo(wLogotipo) {
    var uri = encodeURI(wUrlLogotipo + wLogotipo); 
    var ft = new FileTransfer(); 
    var options = new FileUploadOptions(); 
    var headers={'Authorization':'authHeader'}; 
    ft.download( uri, fileURL, function(entry) { 
        //alert("download complete: " + entry.toURL());
        $("#imgLogotipo").attr("src", entry.toURL());
        try {
            if(typeof(window.localStorage) != 'undefined') {
                window.localStorage.setItem("logotipo", "s");
                }
            else
                {
                alert('window.localStorage, not defined');
                }
            }
            catch(err){
                alert('store_local,error,' + err);
            }
        $.ui.loadContent("#pagPrincipal",true,true,wTipoTransicao);
        }, 
        function(error) { 
            alert("download error source " + error.source); 
            alert("download error target " + error.target); 
            alert("upload error code" + error.code); },
            true, options
    ); 
}

 

 

 

0 Kudos
Nicolas_O_Intel
Employee
454 Views

Hamilton Tenório da Silva wrote:

I use this code:

//função para buscar logotipo do cliente no servidor e guardar no aparelho
function funBaixaLogotipo(wLogotipo) {
    var uri = encodeURI(wUrlLogotipo + wLogotipo); 
    var ft = new FileTransfer(); 
    var options = new FileUploadOptions(); 
    var headers={'Authorization':'authHeader'}; 
    ft.download( uri, fileURL, function(entry) { 
        //alert("download complete: " + entry.toURL());
        $("#imgLogotipo").attr("src", entry.toURL());
        try {
            if(typeof(window.localStorage) != 'undefined') {
                window.localStorage.setItem("logotipo", "s");
                }
            else
                {
                alert('window.localStorage, not defined');
                }
            }
            catch(err){
                alert('store_local,error,' + err);
            }
        $.ui.loadContent("#pagPrincipal",true,true,wTipoTransicao);
        }, 
        function(error) { 
            alert("download error source " + error.source); 
            alert("download error target " + error.target); 
            alert("upload error code" + error.code); },
            true, options
    ); 
}

In addition to Hamilton Tenório da Silva code, I think you should add the File Transfer Cordova Plugin to your project

https://github.com/apache/cordova-plugin-file-transfer

 

0 Kudos
Reply