Skip to content

Commit f9c73ad

Browse files
authored
feat(storage-uploadthing): configurable upload router input config (#11954)
Fixes #11949 by setting the default limit to `512MB`. Additionally, makes this configurable via `clientUploads.routerInputConfig`. Details are here https://docs.uploadthing.com/file-routes#route-config
1 parent 760cfad commit f9c73ad

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

packages/storage-uploadthing/src/getClientUploadRoute.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ type Args = {
1212
req: PayloadRequest
1313
}) => boolean | Promise<boolean>
1414
acl: 'private' | 'public-read'
15+
routerInputConfig?: FileRouterInputConfig
1516
token?: string
1617
}
1718

@@ -22,18 +23,24 @@ import type { FileRouter } from 'uploadthing/server'
2223
import { createRouteHandler } from 'uploadthing/next'
2324
import { createUploadthing } from 'uploadthing/server'
2425

26+
import type { FileRouterInputConfig } from './index.js'
27+
2528
export const getClientUploadRoute = ({
2629
access = defaultAccess,
2730
acl,
31+
routerInputConfig = {},
2832
token,
2933
}: Args): PayloadHandler => {
3034
const f = createUploadthing()
3135

3236
const uploadRouter = {
3337
uploader: f({
38+
...routerInputConfig,
3439
blob: {
3540
acl,
3641
maxFileCount: 1,
42+
maxFileSize: '512MB',
43+
...('blob' in routerInputConfig ? routerInputConfig.blob : {}),
3744
},
3845
})
3946
.middleware(async ({ req: rawReq }) => {

packages/storage-uploadthing/src/index.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,36 @@
11
import type {
22
Adapter,
3-
ClientUploadsConfig,
3+
ClientUploadsAccess,
44
PluginOptions as CloudStoragePluginOptions,
55
CollectionOptions,
66
GeneratedAdapter,
77
} from '@payloadcms/plugin-cloud-storage/types'
88
import type { Config, Field, Plugin, UploadCollectionSlug } from 'payload'
9+
import type { createUploadthing } from 'uploadthing/server'
910
import type { UTApiOptions } from 'uploadthing/types'
1011

1112
import { cloudStoragePlugin } from '@payloadcms/plugin-cloud-storage'
1213
import { initClientUploads } from '@payloadcms/plugin-cloud-storage/utilities'
13-
import { createRouteHandler } from 'uploadthing/next'
14-
import { createUploadthing, UTApi } from 'uploadthing/server'
14+
import { UTApi } from 'uploadthing/server'
1515

1616
import { generateURL } from './generateURL.js'
1717
import { getClientUploadRoute } from './getClientUploadRoute.js'
1818
import { getHandleDelete } from './handleDelete.js'
1919
import { getHandleUpload } from './handleUpload.js'
2020
import { getHandler } from './staticHandler.js'
2121

22+
export type FileRouterInputConfig = Parameters<ReturnType<typeof createUploadthing>>[0]
23+
2224
export type UploadthingStorageOptions = {
2325
/**
2426
* Do uploads directly on the client, to bypass limits on Vercel.
2527
*/
26-
clientUploads?: ClientUploadsConfig
28+
clientUploads?:
29+
| {
30+
access?: ClientUploadsAccess
31+
routerInputConfig?: FileRouterInputConfig
32+
}
33+
| boolean
2734

2835
/**
2936
* Collection options to apply the adapter to.

0 commit comments

Comments
 (0)