| [ Web Proxy ] |
| Viewing: https://developers.cloudflare.com/workers/configuration/multipart-upload-metadata/ | [Back] [Original] |
Note
There is a new API for uploading Workers. Refer to these docs for more information.
If you're using the Workers Script Upload API or Version Upload API directly, multipart/form-data uploads require you to specify a metadata part. This metadata defines the Worker's configuration in JSON format, analogue to the wrangler.toml file.
{
"main_module": "main.js",
"bindings": [
{
"type": "plain_text",
"name": "MESSAGE",
"text": "Hello, world!"
}
],
"compatibility_date": "2021-09-14"
}
Note
See examples of metadata being used with the Workers Script Upload API here.
The following attributes are configurable at the top-level.
Note
At a minimum, the main_module key is required to upload a Worker.
main_module stringrequired
main.js.assets objectoptional
config objectoptional
jwt field provides a token authorizing assets to be attached to a Worker.keep_assets booleanoptional
bindings array[object] optional
placement objectoptional
mode field only supports smart for automatic placement.compatibility_date stringoptional
compatibility_date, otherwise if on upload via the API, it defaults to the oldest compatibility date before any flags took effect (2021-11-02).compatibility_flags array[string] optional
compatibility_date.For immediately deployed uploads, the following additional attributes are configurable at the top-level.
Note
Except for annotations, these attributes are not available for version uploads.
migrations array[object] optional
logpush booleanoptional
tail_consumers array[object] optional
tags array[string] optional
annotations objectoptional
workers/message specifies a custom message for the version.workers/tag specifies a custom identifier for the version.For version uploads, the following additional attributes are configurable at the top-level.
annotations objectoptional
workers/message specifies a custom message for the version.workers/tag specifies a custom identifier for the version.workers/alias specifies a custom alias for this version.Workers can interact with resources on the Cloudflare Developer Platform using bindings. Refer to the JSON example below that shows how to add bindings in the metadata part.
{
"bindings": [
{
"type": "ai",
"name": "<VARIABLE_NAME>"
},
{
"type": "analytics_engine",
"name": "<VARIABLE_NAME>",
"dataset": "<DATASET>"
},
{
"type": "assets",
"name": "<VARIABLE_NAME>"
},
{
"type": "browser_rendering",
"name": "<VARIABLE_NAME>"
},
{
"type": "d1",
"name": "<VARIABLE_NAME>",
"id": "<D1_ID>"
},
{
"type": "durable_object_namespace",
"name": "<VARIABLE_NAME>",
"class_name": "<DO_CLASS_NAME>"
},
{
"type": "hyperdrive",
"name": "<VARIABLE_NAME>",
"id": "<HYPERDRIVE_ID>"
},
{
"type": "kv_namespace",
"name": "<VARIABLE_NAME>",
"namespace_id": "<KV_ID>"
},
{
"type": "mtls_certificate",
"name": "<VARIABLE_NAME>",
"certificate_id": "<MTLS_CERTIFICATE_ID>"
},
{
"type": "plain_text",
"name": "<VARIABLE_NAME>",
"text": "<VARIABLE_VALUE>"
},
{
"type": "queue",
"name": "<VARIABLE_NAME>",
"queue_name": "<QUEUE_NAME>"
},
{
"type": "r2_bucket",
"name": "<VARIABLE_NAME>",
"bucket_name": "<R2_BUCKET_NAME>"
},
{
"type": "secret_text",
"name": "<VARIABLE_NAME>",
"text": "<SECRET_VALUE>"
},
{
"type": "service",
"name": "<VARIABLE_NAME>",
"service": "<SERVICE_NAME>",
"environment": "production"
},
{
"type": "vectorize",
"name": "<VARIABLE_NAME>",
"index_name": "<INDEX_NAME>"
},
{
"type": "version_metadata",
"name": "<VARIABLE_NAME>"
}
]
}| Web Proxy Viewer | New URL | Original Page |