# Upload your profile photo

Source: https://docs.musicnerd.net/api-reference/users/upload-profile-image

Upload your profile photo

## POST /api/user/profile-image

Full OpenAPI specification: https://docs.musicnerd.net/spec/users.json

## Authentication

This operation requires one of the security alternatives in the specification below. Security scheme definitions are included where present in the published specification.

[Authentication guide](https://docs.musicnerd.net/authentication)

## Operation and referenced schemas

```json
{
  "openapi": "3.1.0",
  "info": {
    "title": "Music Nerd API: users and profile",
    "version": "1.0.0",
    "description": "The signed-in user's own account and profile: their user name, profile photo, approved claim, contributed artists, contribution summary and the updates feed. Every route answers about the caller only; the account comes from the token, never from the request."
  },
  "servers": [
    {
      "url": "https://musicnerd-api.vercel.app",
      "description": "Production"
    },
    {
      "url": "https://musicnerd-api-staging.vercel.app",
      "description": "Staging (staging database)"
    }
  ],
  "paths": {
    "/api/user/profile-image": {
      "post": {
        "summary": "Upload your profile photo",
        "operationId": "uploadUserProfileImage",
        "security": [
          {
            "privyBearer": []
          }
        ],
        "description": "Replaces the caller's profile photo with a JPG, PNG or WebP up to 2 MB, saved as a 512×512 WebP with metadata stripped.",
        "parameters": [
          {
            "$ref": "#/components/parameters/ProfileAccountOptional"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "required": [
                  "file"
                ],
                "properties": {
                  "file": {
                    "type": "string",
                    "format": "binary",
                    "description": "A JPG, PNG or WebP image, at most 2 MB."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Stored. `Cache-Control: private, no-store`.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "status",
                    "success"
                  ],
                  "properties": {
                    "status": {
                      "type": "string",
                      "enum": [
                        "ok"
                      ]
                    },
                    "success": {
                      "type": "boolean",
                      "enum": [
                        true
                      ]
                    }
                  }
                },
                "example": {
                  "status": "ok",
                  "success": true
                }
              }
            }
          },
          "400": {
            "description": "No `file`, an empty file, the wrong type, over 2 MB, or an image the decoder rejected.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "badFile": {
                    "summary": "Missing, empty, wrong type or too large",
                    "value": {
                      "status": "error",
                      "error": "Choose a JPG, PNG or WebP image smaller than 2 MB"
                    }
                  },
                  "unreadable": {
                    "summary": "Could not be decoded",
                    "value": {
                      "status": "error",
                      "error": "This image could not be read. Try another JPG, PNG or WebP."
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "No token, an invalid or expired token, or no user row for it.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "status": "error",
                  "error": "Not signed in"
                }
              }
            }
          },
          "409": {
            "description": "`X-Profile-Account` was sent and is not the caller's id.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "status": "error",
                  "error": "Your account changed. Refresh and try again."
                }
              }
            }
          },
          "413": {
            "description": "The request body is larger than 2 MB plus form overhead.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "status": "error",
                  "error": "Choose an image smaller than 2 MB"
                }
              }
            }
          },
          "503": {
            "description": "Storage could not be written.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "status": "error",
                  "error": "Could not save your profile photo. Try again."
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "parameters": {
      "ProfileAccountOptional": {
        "name": "X-Profile-Account",
        "in": "header",
        "required": false,
        "description": "The user id the page believes is signed in. When sent, it must equal the token's user, or the response is 409.",
        "schema": {
          "type": "string",
          "format": "uuid"
        },
        "example": "6f1d2e3a-4b5c-4d6e-8f90-a1b2c3d4e5f6"
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "required": [
          "status",
          "error"
        ],
        "properties": {
          "status": {
            "type": "string",
            "enum": [
              "error"
            ]
          },
          "error": {
            "type": "string"
          }
        }
      }
    },
    "securitySchemes": {
      "privyBearer": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "Access token",
        "description": "The signed-in user's access token. Copy it at https://musicnerd.net/access after signing in. Every route here answers about that user only."
      }
    }
  }
}
```
