zexco2
zexco2

Reputation: 159

Download large file >1GB using http protocol, java and javascript

I have a web application for downloading files. Everything works fine except when I want to download a file more than 1GB .

This is my java code:

InputStream in = new FileInputStream(new File(folderFile.getAbsolutePath()));
                org.apache.commons.io.IOUtils.copy(in, response.getOutputStream());
                response.flushBuffer();
                in.close();

HTTP request :

$http({
            method:'get',
            url:this.apiDownloadFileUrl,
            responseType:'arraybuffer',
            cache: false
    });

and here is client side: I got data successfully on client, but when I make it Blob , if the data size was more than 500MB , nothing happened and it wasn't downloaded. Also, I can download 300MB ...

How can I check if it is a memory problem, or a server problem? ... When I download from gmail , I can download more than 1GB .

            .success(function(databack) {       
                            var file = new Blob([ databack ], {
                                type : 'application/csv'
                            });

                            var fileURL = window.URL.createObjectURL(file);
                            var a = document.createElement('a');
                            a.href = fileURL;
                            a.target = '_blank';
                            a.download = data;
                            document.body.appendChild(a);
                            a.click(); 

Upvotes: 1

Views: 4188

Answers (2)

Alice
Alice

Reputation: 1

You should check the response message first, and decide which side fire the problem. As my experience, you should check whether the file was cached by the browser rather than any problems~

Upvotes: 0

Stefan
Stefan

Reputation: 12453

Have you tried using the copyLarge() methods from IOUtils? For the copy() methods the JavaDoc says:

"For large streams use the copyLarge(InputStream, OutputStream) method."

Upvotes: 1

Related Questions