jszip
jszip copied to clipboard
Google Chrome blocks downloads
I use jszip on https://createapp.dev/ and it works fine on firefox and safari but on chrome I get the error "Google Chrome blocks downloads" and it links to this page https://support.google.com/chrome/answer/6261569?visit_id=636982507927899843-1977983141&p=ib_download_blocked&hl=en&rd=1
It looks like this (the text is in swedish but it says the file "usually is not downloaded and can be harmful")
any ideas?
Also running into the same issue
+1
Same issue. Is there any idea?
I have the same issue here https://i.imgur.com/PLrXLu0.png super confusing and I am guessing it's more related to the format. I did format to my blob in the browser with typescript and the same issue happened to me need a quick fix.
Here is my service zip.service.ts as per suggession in the document.
import {Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
// @ts-ignore
import * as JSZip from 'jszip';
@Injectable({
providedIn: 'root'
})
export class ZipService {
private readonly fileFormatType: string = 'application/zip';
constructor(private http: HttpClient) {
}
/**
* Download files from url to zip contnent
*/
public async downloadFilesInZip(urls: string[]): Promise<Blob> {
const zip: JSZip = new JSZip();
await Promise.all(
urls.map(async (url: string) => {
const fileBlob: Blob = await this.downloadResource(url);
const fileContent: Blob = new Blob([fileBlob], {type: this.fileFormatType});
const fileName: string = url.substring(url.lastIndexOf('/') + 1);
zip.file(`${fileName}`, fileContent, {base64: true});
}));
const zipContent: Blob = await zip.generateAsync({type: 'blob'});
return new Blob([zipContent], {type: this.fileFormatType});
}
/**
* Download resource from url to blob
*/
private async downloadResource(url: string): Promise<Blob> {
const file: Blob = await this.http.get<Blob>(url, {responseType: 'blob' as 'json'}).toPromise();
return file;
}
}
Here is the consumer
const zipContent: Blob = await this.zipSrvice.downloadFilesInZip(zipUrls);
saveAs(zipContent, `${this.name}.zip`);
same issue