Skip to content
Start here

Create authenticated direct upload URL V2

images.v2.direct_uploads.create(DirectUploadCreateParams**kwargs) -> DirectUploadCreateResponse
POST/accounts/{account_id}/images/v2/direct_upload

Direct uploads allow users to upload images without API keys. A common use case are web apps, client-side applications, or mobile devices where users upload content directly to Cloudflare Images. This method creates a draft record for a future image. It returns an upload URL and an image identifier. To verify if the image itself has been uploaded, send an image details request (accounts/:account_identifier/images/v1/:identifier), and check that the draft: true property is not present.

Security
API Token

The preferred authorization scheme for interacting with the Cloudflare API. Create a token.

Example:Authorization: Bearer Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY
API Email + API Key

The previous authorization scheme for interacting with the Cloudflare API, used in conjunction with a Global API key.

Example:X-Auth-Email: user@example.com

The previous authorization scheme for interacting with the Cloudflare API. When possible, use API tokens instead of Global API keys.

Example:X-Auth-Key: 144c9defac04969c7bfad8efaa8ea194
Accepted Permissions (at least one required)
Images Write
ParametersExpand Collapse
account_id: str

Account identifier tag.

maxLength32
id: Optional[str]

Optional Image Custom ID. Up to 1024 chars. Can include any number of subpaths, and utf8 characters. Cannot start nor end with a / (forward slash). Cannot be a UUID.

maxLength1024
creator: Optional[str]

Can set the creator field with an internal user ID.

expiry: Optional[Union[str, datetime]]

The date after which the upload will not be accepted. Minimum: Now + 2 minutes. Maximum: Now + 6 hours.

formatdate-time
metadata: Optional[object]

User modifiable key-value store. Can be used for keeping references to another system of record, for managing images.

require_signed_urls: Optional[bool]

Indicates whether the image requires a signature token to be accessed.

ReturnsExpand Collapse
class DirectUploadCreateResponse:
id: Optional[str]

Image unique identifier.

maxLength32
upload_url: Optional[str]

The URL the unauthenticated upload can be performed to using a single HTTP POST (multipart/form-data) request.

Create authenticated direct upload URL V2

import os
from cloudflare import Cloudflare

client = Cloudflare(
    api_token=os.environ.get("CLOUDFLARE_API_TOKEN"),  # This is the default and can be omitted
)
direct_upload = client.images.v2.direct_uploads.create(
    account_id="023e105f4ecef8ad9ca31a8372d0c353",
)
print(direct_upload.id)
{
  "errors": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "messages": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "result": {
    "id": "id",
    "uploadURL": "https://upload.imagedelivery.net/FxUufywByo0m2v3xhKSiU8/e22e9e6b-c02b-42fd-c405-6c32af5fe600"
  },
  "success": true
}
Returns Examples
{
  "errors": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "messages": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "result": {
    "id": "id",
    "uploadURL": "https://upload.imagedelivery.net/FxUufywByo0m2v3xhKSiU8/e22e9e6b-c02b-42fd-c405-6c32af5fe600"
  },
  "success": true
}