【问题标题】:python and angularjs file downloadpython和angularjs文件下载
【发布时间】:2017-01-24 23:38:55
【问题描述】:

当用户单击 UI 上的下载按钮时,我想下载共享中的文件。它适用于

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

这里是javascript代码

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

有什么建议吗?

【问题讨论】:

  • 其他浏览器是否也出现此问题?
  • 尝试使用curlwget或类似的命令行工具下载文件。然后您可能会看到问题所在,例如您的文件系统的最大文件大小可能为 1GB。
  • 是的,在其他浏览器上也有同样的问题。我们正在使用 uwsgi 和 nginx。我在想我的默认配置只允许 1GB。我尝试使用 proxy_max_temp_file_size 5120m 添加 nginx conf;没有成功。

标签: javascript python angularjs download filesize


【解决方案1】:

我通过将以下参数添加到我的 nginx.conf 文件中解决了这个问题。

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;

    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-03-06
    • 2017-01-24
    • 1970-01-01
    • 1970-01-01
    • 2021-02-13
    • 2015-09-17
    • 2013-12-14
    相关资源
    最近更新 更多