You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: src/content/docs/workers/static-assets/direct-upload.mdx
+66-21
Original file line number
Diff line number
Diff line change
@@ -16,15 +16,18 @@ import {
16
16
TabItem,
17
17
Tabs,
18
18
} from"~/components";
19
+
import { Icon } from"astro-icon/components";
19
20
20
21
:::note
21
22
22
-
Directly uploading assets via APIs is an advanced approach that most users will not need. Instead, we encourage users to deploy your Worker with [Wrangler](/workers/static-assets/get-started/#1-create-a-new-worker-project-using-the-cli).
23
+
Directly uploading assets via APIs is an advanced approach which, unless you are building a programatic integration, most users will not need. Instead, we encourage users to deploy your Worker with [Wrangler](/workers/static-assets/get-started/#1-create-a-new-worker-project-using-the-cli).
23
24
24
25
:::
25
26
26
27
Our API empowers users to upload and include static assets as part of a Worker. These static assets can be served for free, and additionally, users can also fetch assets through an optional [assets binding](/workers/static-assets/binding/) to power more advanced applications. This guide will describe the process for attaching assets to your Worker directly with the API.
curl -X POST https://api.cloudflare.com/client/v4/accounts/{account_id}/workers/scripts/{script_name}/assets-upload-session \
53
70
--header 'content-type: application/json' \
@@ -69,6 +86,31 @@ curl -X POST https://api.cloudflare.com/client/v4/accounts/{account_id}/workers/
69
86
}
70
87
}'
71
88
```
89
+
</TabItem>
90
+
<TabItemicon="cloudflare-for-platforms"label="Workers for Platforms">
91
+
```bash
92
+
curl -X POST https://api.cloudflare.com/client/v4/accounts/{account_id}/workers/dispatch/namespaces/{dispatch_namespace}/scripts/{script_name}/assets-upload-session \
93
+
--header 'content-type: application/json' \
94
+
--header 'Authorization: Bearer <API_TOKEN>' \
95
+
--data '{
96
+
"manifest": {
97
+
"/filea.html": {
98
+
"hash": "08f1dfda4574284ab3c21666d1",
99
+
"size": 12
100
+
},
101
+
"/fileb.html": {
102
+
"hash": "4f1c1af44620d531446ceef93f",
103
+
"size": 23
104
+
},
105
+
"/filec.html": {
106
+
"hash": "54995e302614e0523757a04ec1",
107
+
"size": 23
108
+
}
109
+
}
110
+
}'
111
+
```
112
+
</TabItem>
113
+
</Tabs>
72
114
73
115
The resulting response will contain a JWT, which provides authentication during file upload. The JWT is valid for one hour.
74
116
@@ -110,7 +152,7 @@ Once every file in the manifest has been uploaded, a status code of 201 will be
110
152
111
153
## Create/Deploy New Version
112
154
113
-
[Script](/api/resources/workers/subresources/scripts/methods/update/) and [version](/api/resources/workers/subresources/scripts/subresources/versions/methods/create/) upload endpoints require specifying a metadata part in the form data. Here, we can provide the completion token from the previous (upload assets) step.
155
+
[Script](/api/resources/workers/subresources/scripts/methods/update/), [Version](/api/resources/workers/subresources/scripts/subresources/versions/methods/create/), and [Workers for Platform script](/api/resources/workers_for_platforms/subresources/dispatch/subresources/namespaces/subresources/scripts/methods/update/) upload endpoints require specifying a metadata part in the form data. Here, we can provide the completion token from the previous (upload assets) step.
0 commit comments