Significant-Gravitas/AutoGPT · error · HTTPException

Invalid file type. Allowed: JPEG, PNG, WebP. Got: {content_t

Error message

Invalid file type. Allowed: JPEG, PNG, WebP. Got: {content_type}

What it means

Returned (400) when the uploaded file's declared Content-Type is not in LOGO_ALLOWED_TYPES (JPEG, PNG, WebP). The check uses the multipart header value, not the file's magic bytes, so the label on the part must be one of the allowed MIME types.

Source

Thrown at autogpt_platform/backend/backend/api/features/oauth.py:708

        not (app := await get_oauth_application_by_id(app_id))
        or app.owner_id != user_id
    ):
        raise HTTPException(
            status_code=status.HTTP_404_NOT_FOUND,
            detail="OAuth App not found",
        )

    # Check GCS configuration
    if not settings.config.media_gcs_bucket_name:
        raise HTTPException(
            status_code=status.HTTP_503_SERVICE_UNAVAILABLE,
            detail="Media storage is not configured",
        )

    # Validate content type
    content_type = file.content_type
    if content_type not in LOGO_ALLOWED_TYPES:
        raise HTTPException(
            status_code=status.HTTP_400_BAD_REQUEST,
            detail=f"Invalid file type. Allowed: JPEG, PNG, WebP. Got: {content_type}",
        )

    # Read file content
    try:
        file_bytes = await file.read()
    except Exception as e:
        logger.error(f"Error reading logo file: {e}")
        raise HTTPException(
            status_code=status.HTTP_400_BAD_REQUEST,
            detail="Failed to read uploaded file",
        )

    # Check file size
    if len(file_bytes) > LOGO_MAX_FILE_SIZE:
        raise HTTPException(
            status_code=status.HTTP_400_BAD_REQUEST,

View on GitHub (pinned to 9c8bb5550f)

Solutions

  1. Convert the logo to JPEG, PNG, or WebP before uploading
  2. Set the multipart part's Content-Type explicitly (image/png, image/jpeg, or image/webp)
  3. Do not rely on the file extension — the declared MIME type must match

Example fix

# before
curl -F "logo=@logo.svg" ...
# after
curl -F "logo=@logo.png;type=image/png" ...
Defensive patterns

Strategy: validation

Validate before calling

ALLOWED = {"image/jpeg", "image/png", "image/webp"}
if file.content_type not in ALLOWED:
    raise ValueError(f"convert to JPEG/PNG/WebP first, got {file.content_type}")

Type guard

def is_allowed_logo_type(content_type: str) -> bool:
    return content_type in {"image/jpeg", "image/png", "image/webp"}

Try / catch

if resp.status_code == 400 and "Invalid file type" in resp.text:
        prompt_user_to_convert_image()

Prevention

When it happens

Trigger: Uploading image/svg+xml, image/gif, image/bmp, application/octet-stream, or a mislabeled part (e.g. sending PNG bytes with content type text/plain).

Common situations: Designers exporting SVG or GIF logos; generic HTTP clients defaulting to application/octet-stream; renaming a .gif to .png without changing the MIME header (the header, not extension, is checked).

Related errors


AI-assisted analysis of Significant-Gravitas/AutoGPT@9c8bb5550f (2026-08-14). Data as JSON: /api/errors/1e6cd2fdec552f52. Report an issue: GitHub.