简体   繁体   English

如何使用Angularjs,Java,Tomcat,Spring和REST下载10GB文件?

[英]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. 如果文件很大,则表示Blob未创建,没有足够的内存。 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. 由于不上传大文件而不拆分文件是不明智的做法,因此用户在上载内容的99%时可能会断开连接,因此他需要重新上传整个文件。

An example here : https://flowjs.github.io/ng-flow/ 此处的示例: 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. 此处的一个很好的例子: http : //ryansouthgate.com/2015/12/24/upload-amazon-s3-using-angularjs/和Amazon S3及其SDK。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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