Search code examples
javascriptpythonangularjsdownloadfilesize

python and angularjs file download


When a user clicks on download button on the UI, I want to download a file that is residing on a share. It works good with <1gb data. but large files, it fails. It doesn't give any error, but i can see that the spinner to download on the bottom left hand corner of chrome stops after 1gb. Here is my python code

filename = os.path.basename(pathToFile)
        chunk_size = 8192
        content_type = mime.from_file(pathToFile)
        response = StreamingHttpResponse(FileWrapper(open(pathToFile), chunk_size),
                                         content_type=content_type)
        response['Content-Length'] = os.path.getsize(pathToFile)
        response['Content-Disposition'] = 'attachment; filename="%s"' % filename

Here is javascript code

 $scope.downloadFile = function(path) {
      return "/download_file?file=" + encodeURIComponent("somePath");

Any suggestions?


Solution

  • I solved the issue by adding the below parameters to my nginx.conf file.

    location /<Your download api path> {           
            uwsgi_pass django;
            uwsgi_read_timeout 300s;
    
            uwsgi_buffering off;
            proxy_set_header Connection '';
            proxy_http_version 1.1;
            chunked_transfer_encoding on;
            proxy_cache off;
    
        }