> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.mycargoextra.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.mycargoextra.com/_mcp/server.

# Upload User Avatar

PATCH http://localhost:9000/api/v1/user/avatar
Content-Type: multipart/form-data

Uploads and stores the customer's avatar.

Multipart field: `avatar` required file.

Response fields: `message`.

Possible errors:
- 400: Invalid file type - avatar must be JPEG, PNG, or WEBP.
- 400: No file found - multipart request did not include `avatar`.
- 400: Error uploading image - S3 upload did not return an avatar URL.
- 502: Image upload failed - upstream image/S3 processing failed.
- 400: Missing One or More Required Parameters - required body/query fields were not supplied.
- 401: Unauthorized - token is missing, expired, invalid, or the account/token pair was not found.
- 403: Access denied - gateway traffic guard/rate policy blocked the request.
- 429: Too many requests - gateway rate limit exceeded.
- 500: Unexpected Error - unhandled gateway or downstream service failure.

Reference: https://docs.mycargoextra.com/cargo-extra-gateway-api-copy/user/avatar/upload-user-avatar

## OpenAPI Specification

```yaml
openapi: 3.1.0
info:
  title: collection
  version: 1.0.0
paths:
  /api/v1/user/avatar:
    patch:
      operationId: upload-user-avatar
      summary: Upload User Avatar
      description: >-
        Uploads and stores the customer's avatar.


        Multipart field: `avatar` required file.


        Response fields: `message`.


        Possible errors:

        - 400: Invalid file type - avatar must be JPEG, PNG, or WEBP.

        - 400: No file found - multipart request did not include `avatar`.

        - 400: Error uploading image - S3 upload did not return an avatar URL.

        - 502: Image upload failed - upstream image/S3 processing failed.

        - 400: Missing One or More Required Parameters - required body/query
        fields were not supplied.

        - 401: Unauthorized - token is missing, expired, invalid, or the
        account/token pair was not found.

        - 403: Access denied - gateway traffic guard/rate policy blocked the
        request.

        - 429: Too many requests - gateway rate limit exceeded.

        - 500: Unexpected Error - unhandled gateway or downstream service
        failure.
      tags:
        - subpackage_user.subpackage_user/avatar
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: >-
                  #/components/schemas/user_avatar_Upload User
                  Avatar_Response_200
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: >-
                  #/components/schemas/PatchApiV1UserAvatarRequestBadRequestError
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: >-
                  #/components/schemas/PatchApiV1UserAvatarRequestUnauthorizedError
        '403':
          description: Forbidden
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PatchApiV1UserAvatarRequestForbiddenError'
        '429':
          description: Too Many Requests
          content:
            application/json:
              schema:
                $ref: >-
                  #/components/schemas/PatchApiV1UserAvatarRequestTooManyRequestsError
        '500':
          description: Internal Server Error
          content:
            application/json:
              schema:
                $ref: >-
                  #/components/schemas/PatchApiV1UserAvatarRequestInternalServerError
        '502':
          description: Bad Gateway
          content:
            application/json:
              schema:
                $ref: >-
                  #/components/schemas/PatchApiV1UserAvatarRequestBadGatewayError
      requestBody:
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                avatar:
                  type: string
                  format: binary
              required:
                - avatar
servers:
  - url: http://localhost:9000
    description: http://localhost:9000
components:
  schemas:
    user_avatar_Upload User Avatar_Response_200:
      type: object
      properties:
        key_0:
          type: integer
        key_1:
          type: string
        key_2:
          type: number
          format: double
        key_3:
          type: string
        key_4:
          type: boolean
      required:
        - key_0
        - key_1
        - key_2
        - key_3
        - key_4
      title: user_avatar_Upload User Avatar_Response_200
    PatchApiV1UserAvatarRequestBadRequestError:
      type: object
      properties:
        message:
          type: string
      required:
        - message
      title: PatchApiV1UserAvatarRequestBadRequestError
    PatchApiV1UserAvatarRequestUnauthorizedError:
      type: object
      properties:
        message:
          type: string
      required:
        - message
      title: PatchApiV1UserAvatarRequestUnauthorizedError
    PatchApiV1UserAvatarRequestForbiddenError:
      type: object
      properties:
        message:
          type: string
      required:
        - message
      title: PatchApiV1UserAvatarRequestForbiddenError
    PatchApiV1UserAvatarRequestTooManyRequestsError:
      type: object
      properties:
        message:
          type: string
      required:
        - message
      title: PatchApiV1UserAvatarRequestTooManyRequestsError
    PatchApiV1UserAvatarRequestInternalServerError:
      type: object
      properties:
        message:
          type: string
      required:
        - message
      title: PatchApiV1UserAvatarRequestInternalServerError
    PatchApiV1UserAvatarRequestBadGatewayError:
      type: object
      properties:
        message:
          type: string
      required:
        - message
      title: PatchApiV1UserAvatarRequestBadGatewayError

```

## Examples



**Request**

```json
{
  "avatar": "<file: profile_picture.png>"
}
```

**Response**

```json
{
  "key_0": 12345,
  "key_1": "Avatar uploaded successfully",
  "key_2": 200,
  "key_3": "http://cdn.cargoextra.com/avatars/12345.png",
  "key_4": true
}
```

**SDK Code**

```python user_avatar_Upload User Avatar_example
import requests

url = "http://localhost:9000/api/v1/user/avatar"

files = { "avatar": "open('profile_picture.png', 'rb')" }

response = requests.patch(url, files=files)

print(response.json())
```

```javascript user_avatar_Upload User Avatar_example
const url = 'http://localhost:9000/api/v1/user/avatar';
const form = new FormData();
form.append('avatar', 'profile_picture.png');

const options = {method: 'PATCH'};

options.body = form;

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go user_avatar_Upload User Avatar_example
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "http://localhost:9000/api/v1/user/avatar"

	payload := strings.NewReader("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"avatar\"; filename=\"profile_picture.png\"\r\nContent-Type: application/octet-stream\r\n\r\n\r\n-----011000010111000001101001--\r\n")

	req, _ := http.NewRequest("PATCH", url, payload)

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby user_avatar_Upload User Avatar_example
require 'uri'
require 'net/http'

url = URI("http://localhost:9000/api/v1/user/avatar")

http = Net::HTTP.new(url.host, url.port)

request = Net::HTTP::Patch.new(url)
request.body = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"avatar\"; filename=\"profile_picture.png\"\r\nContent-Type: application/octet-stream\r\n\r\n\r\n-----011000010111000001101001--\r\n"

response = http.request(request)
puts response.read_body
```

```java user_avatar_Upload User Avatar_example
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.patch("http://localhost:9000/api/v1/user/avatar")
  .body("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"avatar\"; filename=\"profile_picture.png\"\r\nContent-Type: application/octet-stream\r\n\r\n\r\n-----011000010111000001101001--\r\n")
  .asString();
```

```php user_avatar_Upload User Avatar_example
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('PATCH', 'http://localhost:9000/api/v1/user/avatar', [
  'multipart' => [
    [
        'name' => 'avatar',
        'filename' => 'profile_picture.png',
        'contents' => null
    ]
  ]
]);

echo $response->getBody();
```

```csharp user_avatar_Upload User Avatar_example
using RestSharp;

var client = new RestClient("http://localhost:9000/api/v1/user/avatar");
var request = new RestRequest(Method.PATCH);
request.AddParameter("undefined", "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"avatar\"; filename=\"profile_picture.png\"\r\nContent-Type: application/octet-stream\r\n\r\n\r\n-----011000010111000001101001--\r\n", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift user_avatar_Upload User Avatar_example
import Foundation
let parameters = [
  [
    "name": "avatar",
    "fileName": "profile_picture.png"
  ]
]

let boundary = "---011000010111000001101001"

var body = ""
var error: NSError? = nil
for param in parameters {
  let paramName = param["name"]!
  body += "--\(boundary)\r\n"
  body += "Content-Disposition:form-data; name=\"\(paramName)\""
  if let filename = param["fileName"] {
    let contentType = param["content-type"]!
    let fileContent = String(contentsOfFile: filename, encoding: String.Encoding.utf8)
    if (error != nil) {
      print(error as Any)
    }
    body += "; filename=\"\(filename)\"\r\n"
    body += "Content-Type: \(contentType)\r\n\r\n"
    body += fileContent
  } else if let paramValue = param["value"] {
    body += "\r\n\r\n\(paramValue)"
  }
}

let request = NSMutableURLRequest(url: NSURL(string: "http://localhost:9000/api/v1/user/avatar")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "PATCH"
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```