@vivinkv28/strapi-provider-uploadthing 0.1.9 → 0.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +114 -213
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,213 +1,114 @@
|
|
|
1
|
-
# @vivinkv28/strapi-provider-uploadthing
|
|
2
|
-
|
|
3
|
-
UploadThing provider for
|
|
4
|
-
|
|
5
|
-
This provider stores Strapi Media Library files in UploadThing
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
'img-src': ["'self'", 'data:', 'blob:', 'https://*.ufs.sh', 'https://utfs.io'],
|
|
116
|
-
'media-src': ["'self'", 'data:', 'blob:', 'https://*.ufs.sh', 'https://utfs.io'],
|
|
117
|
-
upgradeInsecureRequests: null,
|
|
118
|
-
},
|
|
119
|
-
},
|
|
120
|
-
},
|
|
121
|
-
},
|
|
122
|
-
'strapi::cors',
|
|
123
|
-
'strapi::poweredBy',
|
|
124
|
-
'strapi::query',
|
|
125
|
-
'strapi::body',
|
|
126
|
-
'strapi::session',
|
|
127
|
-
'strapi::favicon',
|
|
128
|
-
'strapi::public',
|
|
129
|
-
];
|
|
130
|
-
|
|
131
|
-
export default config;
|
|
132
|
-
```
|
|
133
|
-
|
|
134
|
-
If you already have a `strapi::security` middleware entry, merge these UploadThing domains into your existing CSP directives instead of adding a second `strapi::security` entry.
|
|
135
|
-
|
|
136
|
-
## Public vs Private Files
|
|
137
|
-
|
|
138
|
-
This is the part most people get confused by:
|
|
139
|
-
|
|
140
|
-
- `acl` controls how the file is stored in UploadThing.
|
|
141
|
-
- `privateFiles` controls how Strapi serves the file.
|
|
142
|
-
|
|
143
|
-
Use this combination for public files:
|
|
144
|
-
|
|
145
|
-
```env
|
|
146
|
-
UPLOADTHING_ACL=public-read
|
|
147
|
-
UPLOADTHING_PRIVATE_FILES=false
|
|
148
|
-
```
|
|
149
|
-
|
|
150
|
-
Use this combination for private files:
|
|
151
|
-
|
|
152
|
-
```env
|
|
153
|
-
UPLOADTHING_ACL=private
|
|
154
|
-
UPLOADTHING_PRIVATE_FILES=true
|
|
155
|
-
```
|
|
156
|
-
|
|
157
|
-
If you set only `privateFiles=true`, Strapi will generate signed URLs, but the uploaded file may still be stored with a public ACL depending on your UploadThing configuration.
|
|
158
|
-
|
|
159
|
-
## How Private Files Work
|
|
160
|
-
|
|
161
|
-
When `privateFiles` is enabled:
|
|
162
|
-
|
|
163
|
-
1. The provider tells Strapi that files should be treated as private.
|
|
164
|
-
2. Strapi asks the provider for a signed URL whenever it needs to serve the file.
|
|
165
|
-
3. The provider requests a temporary signed URL from UploadThing using the stored `customId` or `fileKey`.
|
|
166
|
-
4. Strapi returns that temporary URL to the client.
|
|
167
|
-
|
|
168
|
-
The signed URL lifetime is controlled by `signedUrlExpiresIn`.
|
|
169
|
-
|
|
170
|
-
## Provider Options
|
|
171
|
-
|
|
172
|
-
| Option | Type | Default | Description |
|
|
173
|
-
| --- | --- | --- | --- |
|
|
174
|
-
| `token` | `string` | `process.env.UPLOADTHING_TOKEN` | UploadThing token used to initialize `UTApi`. |
|
|
175
|
-
| `acl` | `'public-read' \| 'private'` | `undefined` | ACL passed to UploadThing during upload. Use `'public-read'` for public files or `'private'` for storage-level private files. |
|
|
176
|
-
| `privateFiles` | `boolean` | `false` | Tells Strapi to treat files as private and request signed URLs when serving them. |
|
|
177
|
-
| `contentDisposition` | `'inline' \| 'attachment'` | `'inline'` | Content disposition sent to UploadThing during upload. |
|
|
178
|
-
| `signedUrlExpiresIn` | `number` | `3600` | Signed URL lifetime in seconds. Used when Strapi requests a private file URL. |
|
|
179
|
-
| `uploadConcurrency` | `number` | `1` | Maximum number of concurrent uploads handled by the provider. Values above `25` are capped to `25`. |
|
|
180
|
-
| `uploadRetries` | `number` | `2` | Number of retry attempts for transient UploadThing upload failures. |
|
|
181
|
-
| `useCustomId` | `boolean` | `true` | Uses a deterministic UploadThing `customId` based on the Strapi file hash and extension. |
|
|
182
|
-
| `apiUrl` | `string` | `undefined` | Optional custom UploadThing API URL. |
|
|
183
|
-
| `ingestUrl` | `string` | `undefined` | Optional custom UploadThing ingest URL. |
|
|
184
|
-
| `logLevel` | `string` | `undefined` | Optional UploadThing log level. |
|
|
185
|
-
| `logFormat` | `string` | `undefined` | Optional UploadThing log format. |
|
|
186
|
-
| `isDev` | `boolean` | `undefined` | Optional UploadThing development mode flag. |
|
|
187
|
-
|
|
188
|
-
## Stored Metadata
|
|
189
|
-
|
|
190
|
-
After upload, this provider stores UploadThing-specific metadata in:
|
|
191
|
-
|
|
192
|
-
```txt
|
|
193
|
-
provider_metadata.uploadthing
|
|
194
|
-
```
|
|
195
|
-
|
|
196
|
-
That metadata includes values such as:
|
|
197
|
-
|
|
198
|
-
- `fileKey`
|
|
199
|
-
- `customId`
|
|
200
|
-
- `url`
|
|
201
|
-
- `ufsUrl`
|
|
202
|
-
- `name`
|
|
203
|
-
- `size`
|
|
204
|
-
|
|
205
|
-
## Notes
|
|
206
|
-
|
|
207
|
-
- The provider uses UploadThing `ufsUrl` as the file URL stored in Strapi.
|
|
208
|
-
- If `useCustomId` is enabled, the provider prefers `customId` when generating signed URLs or deleting files.
|
|
209
|
-
- If a deterministic `customId` conflicts during replace-media flows, the provider falls back to a unique ID and retries the upload.
|
|
210
|
-
|
|
211
|
-
## Learn More
|
|
212
|
-
|
|
213
|
-
- [UploadThing](https://uploadthing.com/)
|
|
1
|
+
# @vivinkv28/strapi-provider-uploadthing
|
|
2
|
+
|
|
3
|
+
UploadThing provider for Strapi uploads.
|
|
4
|
+
|
|
5
|
+
This provider stores Strapi Media Library files in UploadThing, offering high-performance, seamless media uploads for Strapi v5 applications.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Requirements
|
|
10
|
+
|
|
11
|
+
- Node.js `>= 20.0.0`
|
|
12
|
+
- Strapi v5
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
Install the provider in your Strapi project:
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm install @vivinkv28/strapi-provider-uploadthing
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## Setup & Configuration
|
|
27
|
+
|
|
28
|
+
### 1. Environment Variables
|
|
29
|
+
Add your UploadThing token and optional configuration variables to your Strapi project's `.env` file:
|
|
30
|
+
|
|
31
|
+
```env
|
|
32
|
+
# UploadThing Token (Required)
|
|
33
|
+
UPLOADTHING_TOKEN=your_uploadthing_token
|
|
34
|
+
|
|
35
|
+
# Optional Configurations
|
|
36
|
+
UPLOADTHING_ACL=public-read
|
|
37
|
+
UPLOADTHING_PRIVATE_FILES=false
|
|
38
|
+
UPLOADTHING_CONTENT_DISPOSITION=inline
|
|
39
|
+
UPLOADTHING_SIGNED_URL_EXPIRES_IN=3600
|
|
40
|
+
UPLOADTHING_UPLOAD_CONCURRENCY=1
|
|
41
|
+
UPLOADTHING_UPLOAD_RETRIES=2
|
|
42
|
+
UPLOADTHING_USE_CUSTOM_ID=true
|
|
43
|
+
UPLOADTHING_LOG_LEVEL=Info
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### 2. Configure Plugin (`./config/plugins.ts`)
|
|
47
|
+
Enable and configure the upload provider in your plugins configuration file:
|
|
48
|
+
|
|
49
|
+
```typescript
|
|
50
|
+
export default ({ env }) => ({
|
|
51
|
+
upload: {
|
|
52
|
+
config: {
|
|
53
|
+
provider: '@vivinkv28/strapi-provider-uploadthing',
|
|
54
|
+
providerOptions: {
|
|
55
|
+
token: env('UPLOADTHING_TOKEN'),
|
|
56
|
+
acl: env('UPLOADTHING_ACL', 'public-read'),
|
|
57
|
+
privateFiles: env.bool('UPLOADTHING_PRIVATE_FILES', false),
|
|
58
|
+
contentDisposition: env('UPLOADTHING_CONTENT_DISPOSITION', 'inline'),
|
|
59
|
+
signedUrlExpiresIn: env.int('UPLOADTHING_SIGNED_URL_EXPIRES_IN', 3600),
|
|
60
|
+
uploadConcurrency: env.int('UPLOADTHING_UPLOAD_CONCURRENCY', 1),
|
|
61
|
+
uploadRetries: env.int('UPLOADTHING_UPLOAD_RETRIES', 2),
|
|
62
|
+
useCustomId: env.bool('UPLOADTHING_USE_CUSTOM_ID', true),
|
|
63
|
+
logLevel: env('UPLOADTHING_LOG_LEVEL', 'Info'),
|
|
64
|
+
},
|
|
65
|
+
actionOptions: {
|
|
66
|
+
upload: {},
|
|
67
|
+
uploadStream: {},
|
|
68
|
+
delete: {},
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### 3. Configure Content Security Policy (`./config/middlewares.ts`)
|
|
76
|
+
To allow UploadThing-hosted media and images to render inside the Strapi Admin Panel and Media Library, update the `contentSecurityPolicy` directives in your security middleware:
|
|
77
|
+
|
|
78
|
+
```typescript
|
|
79
|
+
import type { Core } from '@strapi/strapi';
|
|
80
|
+
|
|
81
|
+
const config: Core.Config.Middlewares = [
|
|
82
|
+
'strapi::logger',
|
|
83
|
+
'strapi::errors',
|
|
84
|
+
{
|
|
85
|
+
name: 'strapi::security',
|
|
86
|
+
config: {
|
|
87
|
+
contentSecurityPolicy: {
|
|
88
|
+
useDefaults: true,
|
|
89
|
+
directives: {
|
|
90
|
+
'connect-src': ["'self'", 'https:'],
|
|
91
|
+
'img-src': ["'self'", 'data:', 'blob:', 'https://*.ufs.sh', 'https://utfs.io'],
|
|
92
|
+
'media-src': ["'self'", 'data:', 'blob:', 'https://*.ufs.sh', 'https://utfs.io'],
|
|
93
|
+
upgradeInsecureRequests: null,
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
'strapi::cors',
|
|
99
|
+
'strapi::poweredBy',
|
|
100
|
+
'strapi::query',
|
|
101
|
+
'strapi::body',
|
|
102
|
+
'strapi::session',
|
|
103
|
+
'strapi::favicon',
|
|
104
|
+
'strapi::public',
|
|
105
|
+
];
|
|
106
|
+
|
|
107
|
+
export default config;
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
---
|
|
111
|
+
|
|
112
|
+
## Learn More
|
|
113
|
+
|
|
114
|
+
- [UploadThing](https://uploadthing.com/)
|