Upload Worker Module
Upload a worker module. You can find more about the multipart metadata on our docs: https://developers.cloudflare.com/workers/configuration/multipart-upload-metadata/.
Security
API Token
The preferred authorization scheme for interacting with the Cloudflare API. Create a token.
Authorization: Bearer Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYYAPI Email + API Key
The previous authorization scheme for interacting with the Cloudflare API, used in conjunction with a Global API key.
X-Auth-Email: user@example.comThe previous authorization scheme for interacting with the Cloudflare API. When possible, use API tokens instead of Global API keys.
X-Auth-Key: 144c9defac04969c7bfad8efaa8ea194Accepted Permissions (at least one required)
Workers Scripts WriteParametersExpand Collapse
params ScriptUpdateParams
Metadata param.Field[ScriptUpdateParamsMetadata]Body param: JSON-encoded metadata about the uploaded parts and Worker configuration.
Body param: JSON-encoded metadata about the uploaded parts and Worker configuration.
Annotations ScriptUpdateParamsMetadataAnnotationsoptionalAnnotations for the version created by this upload.
Annotations for the version created by this upload.
Assets ScriptUpdateParamsMetadataAssetsoptionalConfiguration for assets within a Worker.
Configuration for assets within a Worker.
Config ScriptUpdateParamsMetadataAssetsConfigoptionalConfiguration for assets within a Worker.
Configuration for assets within a Worker.
The contents of a _headers file (used to attach custom headers on asset responses).
The contents of a _redirects file (used to apply redirects or proxy paths ahead of asset serving).
HTMLHandling ScriptUpdateParamsMetadataAssetsConfigHTMLHandlingoptionalDetermines the redirects and rewrites of requests for HTML content.
Determines the redirects and rewrites of requests for HTML content.
NotFoundHandling ScriptUpdateParamsMetadataAssetsConfigNotFoundHandlingoptionalDetermines the response when a request does not match a static asset, and there is no Worker script.
Determines the response when a request does not match a static asset, and there is no Worker script.
RunWorkerFirst ScriptUpdateParamsMetadataAssetsConfigRunWorkerFirstUnionoptionalContains a list path rules to control routing to either the Worker or assets. Glob (*) and negative (!) rules are supported. Rules must start with either '/' or '!/'. At least one non-negative rule must be provided, and negative rules have higher precedence than non-negative rules.
Contains a list path rules to control routing to either the Worker or assets. Glob (*) and negative (!) rules are supported. Rules must start with either '/' or '!/'. At least one non-negative rule must be provided, and negative rules have higher precedence than non-negative rules.
Contains a list path rules to control routing to either the Worker or assets. Glob (*) and negative (!) rules are supported. Rules must start with either '/' or '!/'. At least one non-negative rule must be provided, and negative rules have higher precedence than non-negative rules.
Bindings []ScriptUpdateParamsMetadataBindingoptionalList of bindings attached to a Worker. You can find more about bindings on our docs: https://developers.cloudflare.com/workers/configuration/multipart-upload-metadata/#bindings.
List of bindings attached to a Worker. You can find more about bindings on our docs: https://developers.cloudflare.com/workers/configuration/multipart-upload-metadata/#bindings.
type ScriptUpdateParamsMetadataBindingsWorkersBindingKindAISearch struct{…}
type ScriptUpdateParamsMetadataBindingsWorkersBindingKindAISearchNamespace struct{…}
type ScriptUpdateParamsMetadataBindingsWorkersBindingKindDispatchNamespace struct{…}
The kind of resource that the binding provides.
type ScriptUpdateParamsMetadataBindingsWorkersBindingKindDurableObjectNamespace struct{…}
type ScriptUpdateParamsMetadataBindingsWorkersBindingKindInherit struct{…}
The kind of resource that the binding provides.
type ScriptUpdateParamsMetadataBindingsWorkersBindingKindRatelimit struct{…}
type ScriptUpdateParamsMetadataBindingsWorkersBindingKindR2Bucket struct{…}
The kind of resource that the binding provides.
Jurisdiction ScriptUpdateParamsMetadataBindingsWorkersBindingKindR2BucketJurisdictionoptionalThe jurisdiction of the R2 bucket.
The jurisdiction of the R2 bucket.
type ScriptUpdateParamsMetadataBindingsWorkersBindingKindSendEmail struct{…}
type ScriptUpdateParamsMetadataBindingsWorkersBindingKindService struct{…}
type ScriptUpdateParamsMetadataBindingsWorkersBindingKindSecretKey struct{…}
Algorithm-specific key parameters. Learn more.
Format ScriptUpdateParamsMetadataBindingsWorkersBindingKindSecretKeyFormatData format of the key. Learn more.
Data format of the key. Learn more.
The kind of resource that the binding provides.
Usages []ScriptUpdateParamsMetadataBindingsWorkersBindingKindSecretKeyUsageAllowed operations with the key. Learn more.
Allowed operations with the key. Learn more.
Key data in JSON Web Key format. Required if format is "jwk".
type ScriptUpdateParamsMetadataBindingsWorkersBindingKindWorkflow struct{…}
type ScriptUpdateParamsMetadataBindingsWorkersBindingKindWasmModule struct{…}
type ScriptUpdateParamsMetadataBindingsWorkersBindingKindVPCNetwork struct{…}
Name of the uploaded file that contains the script (e.g. the file adding a listener to the fetch event). Indicates a service worker syntax Worker.
Date indicating targeted support in the Workers runtime. Backwards incompatible fixes to the runtime following this date will not affect this Worker.
Flags that enable or disable certain features in the Workers runtime. Used to enable upcoming features or opt in or out of specific changes not included in a compatibility_date.
Retain assets which exist for a previously uploaded Worker version; used in lieu of providing a completion token.
Name of the uploaded file that contains the main module (e.g. the file exporting a fetch handler). Indicates a module syntax Worker.
Migrations ScriptUpdateParamsMetadataMigrationsoptionalMigrations to apply for Durable Objects associated with this Worker.
Migrations to apply for Durable Objects associated with this Worker.
type SingleStepMigration struct{…}A single set of migrations to apply.
A single set of migrations to apply.
A list of classes to create Durable Object namespaces with SQLite from.
Tag used to verify against the latest migration tag for this Worker. If they don't match, the upload is rejected.
type ScriptUpdateParamsMetadataMigrationsWorkersMultipleStepMigrations struct{…}
Tag used to verify against the latest migration tag for this Worker. If they don't match, the upload is rejected.
Observability ScriptUpdateParamsMetadataObservabilityoptionalObservability settings for the Worker.
Observability settings for the Worker.
The sampling rate for incoming requests. From 0 to 1 (1 = 100%, 0.1 = 10%). Default is 1.
Logs ScriptUpdateParamsMetadataObservabilityLogsoptionalLog settings for the Worker.
Log settings for the Worker.
Whether invocation logs are enabled for the Worker.
Placement ScriptUpdateParamsMetadataPlacementoptionalConfiguration for Smart Placement. Specify mode='smart' for Smart Placement, or one of region/hostname/host.
Configuration for Smart Placement. Specify mode='smart' for Smart Placement, or one of region/hostname/host.
type ScriptUpdateParamsMetadataPlacementObject struct{…}
Enables Smart Placement.
The last time the script was analyzed for Smart Placement.
Status ScriptUpdateParamsMetadataPlacementObjectStatusoptionalStatus of Smart Placement.
Status of Smart Placement.
type ScriptUpdateParamsMetadataPlacementObject struct{…}
The last time the script was analyzed for Smart Placement.
Status ScriptUpdateParamsMetadataPlacementObjectStatusoptionalStatus of Smart Placement.
Status of Smart Placement.
type ScriptUpdateParamsMetadataPlacementObject struct{…}
The last time the script was analyzed for Smart Placement.
Status ScriptUpdateParamsMetadataPlacementObjectStatusoptionalStatus of Smart Placement.
Status of Smart Placement.
type ScriptUpdateParamsMetadataPlacementObject struct{…}
The last time the script was analyzed for Smart Placement.
Status ScriptUpdateParamsMetadataPlacementObjectStatusoptionalStatus of Smart Placement.
Status of Smart Placement.
type ScriptUpdateParamsMetadataPlacementObject struct{…}
The last time the script was analyzed for Smart Placement.
Status ScriptUpdateParamsMetadataPlacementObjectStatusoptionalStatus of Smart Placement.
Status of Smart Placement.
type ScriptUpdateParamsMetadataPlacementObject struct{…}
The last time the script was analyzed for Smart Placement.
Status ScriptUpdateParamsMetadataPlacementObjectStatusoptionalStatus of Smart Placement.
Status of Smart Placement.
type ScriptUpdateParamsMetadataPlacementObject struct{…}
The last time the script was analyzed for Smart Placement.
Status ScriptUpdateParamsMetadataPlacementObjectStatusoptionalStatus of Smart Placement.
Status of Smart Placement.
type ScriptUpdateParamsMetadataPlacementObject struct{…}
Target []ScriptUpdateParamsMetadataPlacementObjectTargetArray of placement targets (currently limited to single target).
Array of placement targets (currently limited to single target).
The last time the script was analyzed for Smart Placement.
Status ScriptUpdateParamsMetadataPlacementObjectStatusoptionalStatus of Smart Placement.
Status of Smart Placement.
Query param: When set to "strict", the upload will fail if any inherit type bindings cannot be resolved against the previous version of the Worker. Without this, unresolvable inherit bindings are silently dropped.
Query param: When set to "strict", the upload will fail if any inherit type bindings cannot be resolved against the previous version of the Worker. Without this, unresolvable inherit bindings are silently dropped.
Body param: An array of modules (often JavaScript files) comprising a Worker script. At least one module must be present and referenced in the metadata as main_module or body_part by filename.
Possible Content-Type(s) are: application/javascript+module, text/javascript+module, application/javascript, text/javascript, text/x-python, text/x-python-requirement, application/wasm, text/plain, application/octet-stream, application/source-map.
ReturnsExpand Collapse
type ScriptUpdateResponse struct{…}
Date indicating targeted support in the Workers runtime. Backwards incompatible fixes to the runtime following this date will not affect this Worker.
Flags that enable or disable certain features in the Workers runtime. Used to enable upcoming features or opt in or out of specific changes not included in a compatibility_date.
The tag of the Durable Object migration that was most recently applied for this Worker.
NamedHandlers []ScriptUpdateResponseNamedHandleroptionalNamed exports, such as Durable Object class implementations and named entrypoints.
Named exports, such as Durable Object class implementations and named entrypoints.
Observability ScriptUpdateResponseObservabilityoptionalObservability settings for the Worker.
Observability settings for the Worker.
The sampling rate for incoming requests. From 0 to 1 (1 = 100%, 0.1 = 10%). Default is 1.
Logs ScriptUpdateResponseObservabilityLogsoptionalLog settings for the Worker.
Log settings for the Worker.
Whether invocation logs are enabled for the Worker.
Placement ScriptUpdateResponsePlacementoptionalConfiguration for Smart Placement. Specify mode='smart' for Smart Placement, or one of region/hostname/host.
Configuration for Smart Placement. Specify mode='smart' for Smart Placement, or one of region/hostname/host.
type ScriptUpdateResponsePlacementObject struct{…}
Enables Smart Placement.
The last time the script was analyzed for Smart Placement.
Status ScriptUpdateResponsePlacementObjectStatusoptionalStatus of Smart Placement.
Status of Smart Placement.
type ScriptUpdateResponsePlacementObject struct{…}
The last time the script was analyzed for Smart Placement.
Status ScriptUpdateResponsePlacementObjectStatusoptionalStatus of Smart Placement.
Status of Smart Placement.
type ScriptUpdateResponsePlacementObject struct{…}
The last time the script was analyzed for Smart Placement.
Status ScriptUpdateResponsePlacementObjectStatusoptionalStatus of Smart Placement.
Status of Smart Placement.
type ScriptUpdateResponsePlacementObject struct{…}
The last time the script was analyzed for Smart Placement.
Status ScriptUpdateResponsePlacementObjectStatusoptionalStatus of Smart Placement.
Status of Smart Placement.
type ScriptUpdateResponsePlacementObject struct{…}
The last time the script was analyzed for Smart Placement.
Status ScriptUpdateResponsePlacementObjectStatusoptionalStatus of Smart Placement.
Status of Smart Placement.
type ScriptUpdateResponsePlacementObject struct{…}
The last time the script was analyzed for Smart Placement.
Status ScriptUpdateResponsePlacementObjectStatusoptionalStatus of Smart Placement.
Status of Smart Placement.
type ScriptUpdateResponsePlacementObject struct{…}
The last time the script was analyzed for Smart Placement.
Status ScriptUpdateResponsePlacementObjectStatusoptionalStatus of Smart Placement.
Status of Smart Placement.
type ScriptUpdateResponsePlacementObject struct{…}
Target []ScriptUpdateResponsePlacementObjectTargetArray of placement targets (currently limited to single target).
Array of placement targets (currently limited to single target).
The last time the script was analyzed for Smart Placement.
Status ScriptUpdateResponsePlacementObjectStatusoptionalStatus of Smart Placement.
Status of Smart Placement.
DeprecatedPlacementStatus ScriptUpdateResponsePlacementStatusoptional
Upload Worker Module
package main
import (
"context"
"fmt"
"github.com/cloudflare/cloudflare-go"
"github.com/cloudflare/cloudflare-go/option"
"github.com/cloudflare/cloudflare-go/workers"
)
func main() {
client := cloudflare.NewClient(
option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"),
)
script, err := client.Workers.Scripts.Update(
context.TODO(),
"this-is_my_script-01",
workers.ScriptUpdateParams{
AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"),
Metadata: cloudflare.F(workers.ScriptUpdateParamsMetadata{
}),
},
)
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", script.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": {
"startup_time_ms": 10,
"id": "this-is_my_script-01",
"compatibility_date": "2021-01-01",
"compatibility_flags": [
"nodejs_compat"
],
"created_on": "2022-05-05T05:15:11.602148Z",
"entry_point": "index.js",
"etag": "777f24a43bef5f69174aa69ceaf1dea67968d510a31d1vw3e49d34a0187c06d1",
"handlers": [
"fetch"
],
"has_assets": false,
"has_modules": false,
"last_deployed_from": "wrangler",
"logpush": false,
"migration_tag": "v1",
"modified_on": "2022-05-20T19:02:56.446492Z",
"named_handlers": [
{
"handlers": [
"class"
],
"name": "MyDurableObject"
}
],
"observability": {
"enabled": true,
"head_sampling_rate": 0.1,
"logs": {
"enabled": true,
"invocation_logs": true,
"destinations": [
"cloudflare"
],
"head_sampling_rate": 0.1,
"persist": true
},
"traces": {
"destinations": [
"cloudflare"
],
"enabled": true,
"head_sampling_rate": 0.1,
"persist": true
}
},
"placement": {
"mode": "smart",
"last_analyzed_at": "2025-01-01T00:00:00Z",
"status": "SUCCESS"
},
"placement_mode": "smart",
"placement_status": "SUCCESS",
"tag": "e8f70fdbc8b1fb0b8ddb1af166186758",
"tags": [
"my-team",
"my-public-api"
],
"tail_consumers": [
{
"service": "my-log-consumer",
"environment": "production",
"namespace": "my-namespace"
}
],
"usage_model": "standard"
},
"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": {
"startup_time_ms": 10,
"id": "this-is_my_script-01",
"compatibility_date": "2021-01-01",
"compatibility_flags": [
"nodejs_compat"
],
"created_on": "2022-05-05T05:15:11.602148Z",
"entry_point": "index.js",
"etag": "777f24a43bef5f69174aa69ceaf1dea67968d510a31d1vw3e49d34a0187c06d1",
"handlers": [
"fetch"
],
"has_assets": false,
"has_modules": false,
"last_deployed_from": "wrangler",
"logpush": false,
"migration_tag": "v1",
"modified_on": "2022-05-20T19:02:56.446492Z",
"named_handlers": [
{
"handlers": [
"class"
],
"name": "MyDurableObject"
}
],
"observability": {
"enabled": true,
"head_sampling_rate": 0.1,
"logs": {
"enabled": true,
"invocation_logs": true,
"destinations": [
"cloudflare"
],
"head_sampling_rate": 0.1,
"persist": true
},
"traces": {
"destinations": [
"cloudflare"
],
"enabled": true,
"head_sampling_rate": 0.1,
"persist": true
}
},
"placement": {
"mode": "smart",
"last_analyzed_at": "2025-01-01T00:00:00Z",
"status": "SUCCESS"
},
"placement_mode": "smart",
"placement_status": "SUCCESS",
"tag": "e8f70fdbc8b1fb0b8ddb1af166186758",
"tags": [
"my-team",
"my-public-api"
],
"tail_consumers": [
{
"service": "my-log-consumer",
"environment": "production",
"namespace": "my-namespace"
}
],
"usage_model": "standard"
},
"success": true
}