我正在尝试从 swagger UI 将 .7z zip 文件上传到快速 api,但我不断收到错误。 文件大小为 120mb。是因为文件太大吗?
如果我上传较小的 zip 大小(例如 16-17 mb),docker 在处理时会自动刷新,我必须一次又一次地上传。
或者什么可能导致此错误?
我正在 docker compose 中运行应用程序,我在 Coolify 中托管 docker-compose。
Code Details
502
Undocumented
Error: response status is 502
Response body
Unrecognized response type; displaying content as text.
Download
Bad Gateway
Response headers
content-length: 11
date: Fri,18 Oct 2024 17:27:56 GMT
vary: Accept-Encoding
@router.post("/7zip/")
async def upload_7zip(background_tasks: BackgroundTasks, archive_file: UploadFile = File(...)):
if not archive_file.filename.endswith(".7z"):
raise HTTPException(status_code=400, detail="Please upload a valid 7z file.")
try:
# Generate a unique filename to avoid overwrites
archive_filename = f"{uuid.uuid4()}_{archive_file.filename}"
archive_path = os.path.join(UPLOAD_DIR, archive_filename)
# Save the uploaded file
with open(archive_path, "wb") as buffer:
shutil.copyfileobj(archive_file.file, buffer)
# Add the extraction task to the background
background_tasks.add_task(extract_file, archive_path)
return JSONResponse({"message": "File uploaded successfully, extraction is in progress."})
except Exception as e:
logger.error(f"An error occurred while processing the 7z file: {str(e)}")
raise HTTPException(status_code=500, detail="An error occurred while processing the 7z file.")
应用程序 docker-compose
app:
container_name: search
build: .
command: bash -c "alembic upgrade head && uvicorn main:app --host 0.0.0.0 --port 8000 --timeout-keep-alive=240"
ports:
- 8001:8000
env_file:
- .env
volumes:
- uploads_data:/app/uploads
depends_on:
- db
restart: always
尝试将
--limit-max-request-body=200000000
添加到您的命令中