Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

VerburgtJimmy's avatar

Download of a zip file with sub folders gives a empty response

I have a function to download a zip file with or without folders based on the file_type_id. However my local setup is returning a empty 200 response with (failed)net::ERR_FAILED. When i look at the temp folder where i created the zip file it is there and all the files are in it when i unzip it in the command line. So my question would be why this behaviour exists and if someone got a solution? I also get all the good logs in the laravel.log so no errors or that the file could not be found

And this is the zipdocuments function

I just call the endpoint using my angular application like this:

downloadZip(id, file_type): any {
    return this.http.get('/audits/downloadzip/'+file_type+'/'+id, {observe: 'response', responseType: 'blob', headers: new HttpHeaders({'Cache-Control': 'no-cache'})});
  }

and this gives the following message in the console and the response is empty

auditor-reservation-…ge.component.ts:174 
 GET /api/audits/downloadzip/1/2 net::ERR_FAILED 200 (OK)

Also a very weird thing is that when i add a readfile($zip_file) before i return the response i get a cors error but when i then use a browser extension to get rid of the cors error i get the file i expected. I am just stuck why it just isn't working in the first place

0 likes
4 replies
Glukinho's avatar

Please give dd($zip_file) right before return response()->download(...

Is this situation only about generated zip files or any file at all? Try to download existing file (put it somewhere before manually) instead of your zip - will it be downloaded?

return response()->download('/tmp/existing-file.zip', 'wrapper.zip', [
    'Content-Type' => 'application/zip',
        ]);

Are files downloaded correctly with direct browser request, not using js libraries?

VerburgtJimmy's avatar

When i add dd in front of the response i get a cors error first. Then when enabeling the cors extension in the browser it returns the full path to the zip: projecten\stv\stv-api\public\wrapper_1750749315.zip . Single file downloads work just fine it is just this function. And the single file downloads use almost the exact same code for the download. I am downloading my files like this in the front-end but when the response is empty with the errfailed it doesn't get to the response console log

this.auditorService.downloadZip(this.reservation.id, file_type).subscribe({
      next: (response) => {
        console.log("resposnse"+ response);
        // let blob: any = new Blob([response.body], {
        //   type: response.body.type + "; charset=utf-8",
        // });
        // fileSaver.saveAs(
        //   blob,
        //   this.reservation.contact.insurer.naam +
        //     "_" +
        //     this.pipe.transform(this.reservation.planning_day, "MM/dd/yyyy") +
        //     (file_type == 2 ? "_documenten.zip" : ".zip")
        // );

        const blob = new Blob([response.body], { type: 'application/zip' });
        const url = window.URL.createObjectURL(blob);
        const a = document.createElement('a');
        a.href = url;
        a.download = this.reservation.contact.insurer.naam +
            "_" +
            this.pipe.transform(this.reservation.planning_day, "MM/dd/yyyy") +
            (file_type == 2 ? "_documenten.zip" : ".zip");
        a.click();
        win

Edit i already tried with the function that is commented out but it gives the same result as this Edit and when i download a existing zip file that is not created using code i get the same but also when using the download function that does work with single files when i want to download a zip file it doesn't even work with that function either

Glukinho's avatar

@VerburgtJimmy it turns out the issue is related to frontend/JS/angular, right? Simple browser request downloads the file successfully?

Please or to participate in this conversation.