jszip icon indicating copy to clipboard operation
jszip copied to clipboard

Google Chrome blocks downloads

Open jakoblind opened this issue 5 years ago • 5 comments

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")

image

any ideas?

jakoblind avatar Jul 09 '19 07:07 jakoblind

Also running into the same issue

lucasvocos avatar Aug 29 '19 02:08 lucasvocos

+1

judemanutd avatar Sep 27 '19 18:09 judemanutd

Same issue. Is there any idea?

zhengjunxin avatar Dec 11 '19 08:12 zhengjunxin

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`);

sameh-g avatar Dec 20 '19 10:12 sameh-g

same issue

ZekiJohn avatar Aug 23 '21 15:08 ZekiJohn