0

When I download small file , everything is OK , but I need some way to download large files . If file large, Blob didn't created , haven't enough memory. Download file without save on client , directly save to disk with many requests on the server or something like that.

My code on server is :

@RequestMapping(value = "/oneFile/{name}", method = RequestMethod.GET)
    public void getOneFile( @PathVariable("name") String name, HttpServletResponse response,HttpServletRequest request) {
                ....
                InputStream in = new FileInputStream(new File(file.getAbsolutePath()));
                org.apache.commons.io.IOUtils.copy(in, response.getOutputStream());
                response.flushBuffer();

On client and this is work for small size:

backupFileServer.downloadOneFileBrow(data)
                        .success(function(databack) {

                            var file = new Blob([ databack ], {
                                type : 'application/csv'
                            });
                            var fileURL = URL.createObjectURL(file);
                            var a = document.createElement('a');
                            a.href = fileURL;
                            a.target = '_blank';
                            a.download = data;
                            document.body.appendChild(a);
                            a.click();
                        })
                        .error(function() {
                            alert($scope.DOWNLOAD_ERROR);
                        });

I tried something like this but didn't work :

var a = document.createElement('a');
                               a.href = 'data:attachment/csv;charset=utf-8,' + encodeURI(databack);
                               a.target = '_blank';
                               a.download = data;
                               document.body.appendChild(a);
                               a.click();

How someone idea how to do this or some example or code ....
Thank you in advance

5
  • It is just not the right solution for the problem. You should think in the direction of other ways, e.g. FTP, BitTorrent, ... Jan 18, 2016 at 9:42
  • I would like if possible without FTP or BitTorrent or something like that ... if possible ... if not , I will must on that way .
    – zexco2
    Jan 18, 2016 at 9:48
  • You have a 10GB csv file?
    – Kayaman
    Jan 18, 2016 at 10:12
  • It remains one of the ways, type is not problem. If I download zip file of 500MB , everything works fine , but if I download zip file of 2GB or larger sizes I have problem from question .
    – zexco2
    Jan 18, 2016 at 10:22
  • my app is using spring boot service from where i am trying to send the 400 MB zip file to client.. but Save File box appears too late approx after 15 min .. not sure y .. my UI is Angular .. nto sure what wrong m doing May 6, 2020 at 19:16

1 Answer 1

3

You need to split your file into multiple files and rebuild the file with your server. Because it's bad practice to upload a big file without splitting it, the user can be disconnect at 99% of the upload and he need to upload the whole file again.

An example here : https://flowjs.github.io/ng-flow/

A good example here : http://ryansouthgate.com/2015/12/24/upload-amazon-s3-using-angularjs/ with Amazon S3 and their SDK.

2
  • This is going to be helpful, but if I understand this is to upload the file, I need something to download file ?
    – zexco2
    Jan 18, 2016 at 10:00
  • yes it's the same for download if you have a large file you need to split it into small chunks and the browser will recompile all the file at the end. Like mega.nz does I think. More informations here : stackoverflow.com/a/27948228/861206
    – rbinsztock
    Jan 18, 2016 at 13:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.