[英]Upload large file from django to cloud storage
I have a django app on Cloud Run and I'd like to create an endpoint that will be called by another python script.我在 Cloud Run 上有一个 django 应用程序,我想创建一个将由另一个 python 脚本调用的端点。 This endpoint should save files to Google storage.
此端点应将文件保存到 Google 存储。 The file size is 800Mb max.
文件大小最大为 800Mb。
So when I try to do this I receive: 413 Request Entity Too Large.因此,当我尝试这样做时,我收到:413 请求实体太大。
So from digging the internet I understood that I should use chunk file.所以通过挖掘互联网我明白我应该使用块文件。 But there is something I do not understand..
但是有一点我不明白..
From this: https://github.com/django/daphne/issues/126 I understand that daphne is now able to receive large body in request.从这里: https : //github.com/django/daphne/issues/126我了解到 daphne 现在能够在请求中接收大型体。 So, I thought that, even receiving a big file Django was managing to chunk it and send it piece by piece.
所以,我认为,即使接收到一个大文件,Django 也设法将它分块并一块一块地发送。
I am curious, Is there anyway to do what I want other than doing manual chunk ?我很好奇,除了手动分块之外,还有什么我想做的吗?
For now I added this to my settings:现在我将此添加到我的设置中:
GS_BLOB_CHUNK_SIZE = 524288
DATA_UPLOAD_MAX_MEMORY_SIZE = 26214400
FILE_UPLOAD_MAX_MEMORY_SIZE = 26214400
and I simply use generics.ListCreateAPIView
with default value for file upload handler.我只是使用
generics.ListCreateAPIView
和文件上传处理程序的默认值。
Generally a 413 error means a size limit in a request has been exceeded.通常413 错误意味着已超出请求中的大小限制。 For Cloud Run, the quota for requests is 32mb .
对于 Cloud Run,请求的配额为32mb 。 According to the documentation, the recommended way of uploading large files is through providing a Signed URL to the Cloud Storage Bucket, since Signed URLs can be used for resumable uploads :
根据文档,上传大文件的推荐方式是向 Cloud Storage Bucket 提供签名 URL ,因为签名 URL 可用于可恢复上传:
Resumable uploads are the recommended method for uploading large files, because you do not have to restart them from the beginning if there is a network failure while the upload is underway.
可恢复上传是上传大文件的推荐方法,因为如果在上传过程中出现网络故障,您不必从头重新启动它们。
You can generate a signed URL from your server backend and use it to upload a file without restrictions from your client side script .您可以从服务器后端生成签名 URL ,并使用它上传文件,而不受客户端脚本的限制。 There appears to be other related questions in which Django servers in Cloud Run have upload limits, and the use of Signed URLS is recommended to deal with these cases.
似乎还有其他相关问题,其中 Cloud Run 中的 Django 服务器有上传限制,建议使用 Signed URLS 来处理这些情况。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.