I am writing code which grab file store in database and send it as a response to client. But when i click on download button, it is sending empty text file as a response, but i need zip file. Where am i doing wrong? Could anyone help with this?

I have search on web and even on stackoverflow but didn't find any luck.

Method which grab all the uploaded files

```
public List<Filestore> documentCollectionBvg(Application app){
        List<Filestore> candidateDocuments = new ArrayList<>();
        Filestore profilePic = app.getCandidate().getProfilePic();
        if(profilePic!=null){
        candidateDocuments.add(profilePic);}
        Filestore panDoc = app.getCandidate().getPanDocument();
        if(panDoc!=null){
        candidateDocuments.add(panDoc);}
        Filestore aadharDoc = app.getCandidate().getAadhaarDocument();
        if(aadharDoc!=null){
            candidateDocuments.add(aadharDoc);
        }
        Filestore salarySlip = app.getCandidate().getSalarySlipDocument();
        if(salarySlip!=null){
        candidateDocuments.add(salarySlip);}
        Filestore passportDoc = app.getCandidate().getPassportDocument();
        if(passportDoc!=null){
        candidateDocuments.add(passportDoc);}
        return candidateDocuments;
}

```

controller

```
@GetMapping(value = "application/get-file", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
    public @ResponseBody byte[] getFile(@RequestParam("appId")String appId) throws IOException {
        NDataUtils nDataUtils=new NDataUtils();
        Application app=applicationService.findByEncryptedId(appId);
        BgvDocumentsDownload bgv=new BgvDocumentsDownload();
        List<Filestore> srcFiles=bgv.documentCollectionBvg(app);
        FileOutputStream fos = new FileOutputStream("multiCompressed.zip");
        ZipOutputStream zipOut = new ZipOutputStream(fos);
        FileInputStream fis=null;
        for (Filestore srcFile : srcFiles) {
            File fileToZip = new File(nDataUtils.getnDataPath()+srcFile.getFullFilePath());
            fis = new FileInputStream(fileToZip);
            ZipEntry zipEntry = new ZipEntry(fileToZip.getName());
            zipOut.putNextEntry(zipEntry);

            byte[] bytes = new byte[1024];
            int length;
            while((length = fis.read(bytes)) >= 0) {
                zipOut.write(bytes, 0, length);
            }
        }
        zipOut.close();
        fos.close();
        return IOUtils.toByteArray(fis);
    }

```

Here NDataUtils is a class which return path for where. So don't get confuse with it.

After i click on download link, a file named **"download"** is download which is just a text file and complete empty.

If anyone can help, this will be kind of you.