简体   繁体   English

从django上传大文件到云存储

[英]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.

相关问题 Django - 使用进度条将文件上传到云(Azure Blob 存储) - Django - upload a file to the cloud (Azure blob storage) with progress bar 使用 django-storages 在谷歌云存储中上传文件的 404 - 404 on file upload in google cloud storage with django-storages Django、Heroku、boto:直接文件上传到谷歌云存储 - Django, Heroku, boto: direct file upload to Google cloud storage 在 Python/Django 中从 Google Cloud Storage/ Buckets 上传和检索文件 - Upload and retrieve files from Google Cloud Storage/ Buckets in Python/Django Django 2:使用 google-cloud-storage 将媒体上传到 Google Cloud Storage - Django 2: upload media to Google Cloud Storage with google-cloud-storage 将文件从 Docker 容器上传到 Google Cloud Storage - File upload from Docker container to Google Cloud Storage 如何使用 Google App Engine + Django 和 JQuery File Upload 将大文件上传到 Google Storage - How to upload large files to Google Storage using Google App Engine + Django and JQuery File Upload django python cumulus-如何处理将大量文件上传到云文件存储 - django python cumulus - How to deal with uploading a large number of files to cloud file storage 如何从 Django 中的 Cloud Run 下载大文件 - How to download large file from Cloud Run in Django Django - React - 谷歌云存储 SigedURL 上传不起作用 - Django - React - Google Cloud Storage SigedURL upload is not working
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM