上传大于 1 MB 的文件时出现 AWS 断开管道错误



我是一个django新手,我继承了一个django后端,几乎没有文档。我正在向托管在AWS上的所述服务器发出请求。为了将文件存储在请求中,我们使用 S3。我在 django 代码上没有发现任何限制文件上传大小的内容,我怀疑可能是 AWS 由于文件大小而关闭了连接。

这是我使用的代码,每当文件的总大小超过 1 MB 时,我都会收到错误:

import requests
json_dict = {'key_1':'value_1','video':video,'image':,image}
requests.post('https://api.test.whatever.io/v1/register', json=dict_reg)

视频是采用 base64 编码的视频文件(".mov"、".avi"、".mp4"等(,图像是采用 base64 编码的图像文件(".jpg"、".png"(。

这是我得到的跟踪,仅当总大小超过 1 MB 时:

/usr/local/lib/python2.7/dist-
packages/requests/packages/urllib3/util/ssl_.py:132: InsecurePlatfo
rmWarning: A true SSLContext object is not available. This prevents urllib3 
from configuring SSL
appropriately and may cause certain SSL connections to fail. You can upgrade 
to a newer version of Python to solve this. For more information, see 
https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
InsecurePlatformWarningTraceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/requests/api.py", line 110, in 
post
return request('post', url, data=data, json=json, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/requests/api.py", line 56, in 
request
return session.request(method=method, url=url, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 
488, in request
resp = self.send(prep, **send_kwargs)
File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 
609, in send
r = adapter.send(request, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/requests/adapters.py", line 
473, in send
raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', error(32, 
'Broken pipe'))

如前所述,我在 django 代码中没有找到文件大小的限制,有什么提示我应该在哪里看吗?我也没有在 AWS S3 策略上找到任何内容。

假设你有一个Nginx来反向代理你的HTTP请求? 如果是,请检查此链接。

另请参阅在 django 中的上传处理程序设置中为以下值设置的值

FILE_UPLOAD_MAX_MEMORY_SIZE

最后是nginx配置。 将nginx.conf文件中的变量client_max_body_size1M更改为2M就可以了。

最新更新