我目前有一個 Fastapi App Engine 應用程式。它處理來自表單的檔案上傳,處理檔案,將其記錄添加到資料庫,并將檔案保存在 Google Cloud 存盤桶中。但是,應用引擎將 POST 請求的檔案上傳大小限制為 35mb。我可以在本地測驗應用程式,它運行良好,但 GCloud GFE 會導致端點為任何大檔案回傳狀態代碼 413。下面你可以看到我用來處理檔案上傳的代碼。
@router.post('/upload')
def upload(name: str = Form(...), file: UploadFile = File(...), db=Depends(get_session)):
"""
Uploads a file to the server
"""
if not file.content_type.startswith('video/'):
error = "File must be a video"
return RedirectResponse(url='/files?error_message=' error, status_code=302)
create_db_record(db, name, file)
storage_client = storage.Client.from_service_account_json('service_account.json')
bucket = storage_client.get_bucket('myapp.appspot.com')
blob = bucket.blob(file.filename)
blob.upload_from_file(file.file)
return RedirectResponse(url='/')
如果我要直接將檔案上傳到存盤桶,我將無法先處理它,但如果它超過 35mb,則無法通過上傳表單發送它。如何允許此 Fastapi 發布請求接受更大的檔案以便能夠上傳到存盤桶?我發現的所有檔案都沒有顯示如何從 fastapi/django 端處理它。
uj5u.com熱心網友回復:
限制為 32MB。您無法更改該限制(配額)。
該值是在 Google 前端 (GFE) 確定/配置的,它是大部分 Google 的全球服務。App Engine、Cloud Run 和 Cloud Functions 等服務具有相同的限制。
App Engine 也有 32 MB 的檔案大小限制。
Google Compute Engine 對檔案大小或上傳大小沒有相同的限制。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/516629.html
標籤:Google Cloud Collective 谷歌应用引擎上传文件谷歌云存储快速API
