@vivinkv28/strapi-provider-uploadthing 0.1.8 → 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.
Files changed (2) hide show
  1. package/README.md +114 -213
  2. package/package.json +4 -4
package/README.md CHANGED
@@ -1,213 +1,114 @@
1
- # @vivinkv28/strapi-provider-uploadthing
2
-
3
- UploadThing provider for the Strapi Uploads
4
-
5
- This provider stores Strapi Media Library files in UploadThing while keeping file records and metadata inside Strapi.
6
-
7
- ## What This Provider Does
8
-
9
- - Uploads Strapi media files to UploadThing
10
- - Stores UploadThing metadata in `provider_metadata.uploadthing`
11
- - Uses the UploadThing file URL as the Strapi file URL
12
- - Supports both `upload` and `uploadStream`
13
- - Supports signed URLs for private files
14
- - Deletes the remote file when the Strapi file is deleted
15
- - Uses predictable `customId` values by default
16
- - Retries transient upload failures automatically
17
- - Handles replace-media conflicts more safely
18
-
19
- ## Requirements
20
-
21
- - Node.js `>= 20.0.0`
22
- - Strapi v5
23
-
24
- ## Installation
25
-
26
- Install the provider in your Strapi project:
27
-
28
- ```bash
29
- npm install @vivinkv28/strapi-provider-uploadthing
30
- ```
31
-
32
- ## Quick Start
33
-
34
- 1. Add your UploadThing token to `.env`.
35
- 2. Configure the upload provider in `config/plugins.ts`.
36
- 3. Update `config/middlewares.ts` so Strapi allows UploadThing media URLs in the admin.
37
- 4. Restart Strapi.
38
-
39
- ## Environment Variables
40
-
41
- Minimum required:
42
-
43
- ```env
44
- UPLOADTHING_TOKEN=your_uploadthing_token
45
- ```
46
-
47
- Typical public-file setup:
48
-
49
- ```env
50
- UPLOADTHING_TOKEN=your_uploadthing_token
51
- UPLOADTHING_ACL=public-read
52
- UPLOADTHING_PRIVATE_FILES=false
53
- UPLOADTHING_CONTENT_DISPOSITION=inline
54
- UPLOADTHING_SIGNED_URL_EXPIRES_IN=3600
55
- UPLOADTHING_UPLOAD_CONCURRENCY=1
56
- UPLOADTHING_UPLOAD_RETRIES=2
57
- UPLOADTHING_USE_CUSTOM_ID=true
58
- UPLOADTHING_LOG_LEVEL=Info
59
- ```
60
-
61
- Typical private-file setup:
62
-
63
- ```env
64
- UPLOADTHING_TOKEN=your_uploadthing_token
65
- UPLOADTHING_ACL=private
66
- UPLOADTHING_PRIVATE_FILES=true
67
- UPLOADTHING_SIGNED_URL_EXPIRES_IN=3600
68
- ```
69
-
70
- ## Strapi Configuration
71
-
72
- Create or update `./config/plugins.ts`:
73
-
74
- ```ts
75
- export default ({ env }) => ({
76
- upload: {
77
- config: {
78
- provider: '@vivinkv28/strapi-provider-uploadthing',
79
- providerOptions: {
80
- token: env('UPLOADTHING_TOKEN'),
81
- acl: env('UPLOADTHING_ACL', 'public-read'),
82
- privateFiles: env.bool('UPLOADTHING_PRIVATE_FILES', false),
83
- contentDisposition: env('UPLOADTHING_CONTENT_DISPOSITION', 'inline'),
84
- signedUrlExpiresIn: env.int('UPLOADTHING_SIGNED_URL_EXPIRES_IN', 3600),
85
- uploadConcurrency: env.int('UPLOADTHING_UPLOAD_CONCURRENCY', 1),
86
- uploadRetries: env.int('UPLOADTHING_UPLOAD_RETRIES', 2),
87
- useCustomId: env.bool('UPLOADTHING_USE_CUSTOM_ID', true),
88
- logLevel: env('UPLOADTHING_LOG_LEVEL', 'Info'),
89
- },
90
- actionOptions: {
91
- upload: {},
92
- uploadStream: {},
93
- delete: {},
94
- },
95
- },
96
- },
97
- });
98
- ```
99
-
100
- Update `./config/middlewares.ts` as well. This step is required so Strapi's Content Security Policy allows UploadThing-hosted images and media to load in the admin panel and Media Library:
101
-
102
- ```ts
103
- import type { Core } from '@strapi/strapi';
104
-
105
- const config: Core.Config.Middlewares = [
106
- 'strapi::logger',
107
- 'strapi::errors',
108
- {
109
- name: 'strapi::security',
110
- config: {
111
- contentSecurityPolicy: {
112
- useDefaults: true,
113
- directives: {
114
- 'connect-src': ["'self'", 'https:'],
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/)
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@vivinkv28/strapi-provider-uploadthing",
3
- "version": "0.1.8",
3
+ "version": "0.1.10",
4
4
  "description": "UploadThing provider for the Strapi Upload plugin",
5
5
  "repository": {
6
6
  "type": "git",
7
- "url": "git+https://github.com/vivinkv28/strapi-provider-uploadthing.git"
7
+ "url": "git+https://github.com/vivinkv6/strapi-upload-things.git"
8
8
  },
9
- "homepage": "https://github.com/vivinkv28/strapi-provider-uploadthing#readme",
9
+ "homepage": "https://github.com/vivinkv6/strapi-upload-things#readme",
10
10
  "bugs": {
11
- "url": "https://github.com/vivinkv28/strapi-provider-uploadthing/issues"
11
+ "url": "https://github.com/vivinkv6/strapi-upload-things/issues"
12
12
  },
13
13
  "main": "index.js",
14
14
  "exports": {