javascript - Saving images from URL using JSzip -
I am using JSzip to download HTML of a div. Div has images inside it (they are not base 64 encoded) Is there a way that I can use JSZ to download files from my Image Path URL? Or should they be 64 encoded?
My current code is just the original demo code from JSzip site ()
var zip = new JSZip (); Var email = $ ('results'). Html (); Zip.file ("test.html", email); Var content = zip.generate ({type: "blob"}); // View FileSaver.js saveAs (content, "example.zip");
First you need to download all the images with Ajax. If they are on the same domain you are in luck, otherwise you need a corse or proxy.
var xhr = new XMLHttpRequest (); Xhr.addEventListener ('Load', function () (if (xhr.status == 200) {// something with xhr.response (not response text), which should be a blob}}); Xhr.open ( 'GET', 'http: //target.url'); Xhr.responseType = 'blob'; xhr.send (zero); When you get the image, Src >> all must be manipulated in and lt; img & gt; , or you replace them with base64 or they were referenced in a folder, you can use them with JSZip Folder is entered
var reader = new FileReader (); Reid Kolod = function () {showout.value = this.result;}; reader.readAsDataURL (xhr.response);
Comments
Post a Comment