Download images from firebase using javascript/jquery -
i´m trying create gallary user gonna able download photos clicking on 1 of then, photos , url of each 1 of photos storaged in firebase realtime database , firebase storage.
this code i´m using download photos onclick event.
html
<div class="photo"> <img class="img-responsive" src="{{url}}" alt="" data-name="{{name}}"> <a class="download" href="{{url}}" download="{{name}}"><span class="icon-download"></span></a> </div> js code
$('#photos_container').on('click','.photo a.download', function(e){ var fileurl = $(this).attr('href'); console.log(fileurl); $(this).attr('href', 'data:application/octet-stream:base64,' + encodeuricomponent(fileurl)); }); the problem when download photo , open black screen.
i try using xmlhttpresquest.
e.preventdefault(); var lnk = this, xhr = new xmlhttprequest(); xhr.open("get", lnk.dataset.link); xhr.responsetype = "blob"; xhr.overridemimetype("octet/stream"); xhr.onload = function() { if (xhr.status === 200) { window.location = (url || webkiturl).createobjecturl(xhr.response); } }; xhr.send(); but problem miss extension in filename. need this. can give guys.
Comments
Post a Comment