User_4373
User_4373

Reputation: 297

Undocumented Error: response status is 502 displaying content as text

I am trying to upload the .7z zip file to the fast api from the swagger UI, but i keep on getting the error. The file size is 120mb. Is it due to the file size being large?

And if i upload the smaller zip size like 16-17 mb the docker gets on refreshing automatically, while processing, and I had to upload again and again.

or what might be causing this error?

I am running the application in docker compose, where i am hosting the docker-compose in coolify.

enter image description here

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.")

app 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

Upvotes: 1

Views: 65

Answers (1)

poisoned_monkey
poisoned_monkey

Reputation: 434

Try to add --limit-max-request-body=200000000 to your command

Upvotes: 0

Related Questions