简体   繁体   中英

How to download 10GB file with Angularjs, Java, Tomcat,Spring and REST?

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM