Skip to content

refactor!: centralize client upload instructions in Payload core - #17312

Merged
AlessioGr merged 26 commits into
mainfrom
refactor/client-uploads
Jul 16, 2026
Merged

AlessioGr merged 26 commits into
mainfrom
refactor/client-uploads

Conversation

@AlessioGr

@AlessioGr AlessioGr commented Jul 13, 2026 •

Copy link
Copy Markdown
Member

Previously, each storage adapter had its own upload endpoint and Admin handler. This worked for the Admin Panel, but other tools had no standard way to upload files.

This PR adds one standardized endpoint that lives in Payload Core:

POST /api/upload-instructions

Payload checks the request and returns upload instructions. These instructions tell the caller where and how to upload the file, whether that uses a signed URL (e.g. S3) or a provider-specific uploader (e.g. uploadthing, vercel).

The Admin Panel uses these instructions now, and MCP can use them later without passing large files as base64. Files still upload directly to the storage provider where supported, and document creation does not change.

Example: S3 Admin Upload Flow

This example uploads cat.jpg to the media collection with the prefix gallery.

Before This PR (main)

Payload startup
  -> s3Storage({ clientUploads: true, collections: { media: true } })
  -> S3 registers /api/storage-s3-generate-signed-url endpoint
  -> S3 register Admin handler client component for "media"

Admin page load
  -> S3ClientUploadHandler builds this URL:
       https://cms.example.com/api/storage-s3-generate-signed-url

User selects cat.jpg and saves
  -> POST https://cms.example.com/api/storage-s3-generate-signed-url
     body = { collectionSlug: "media", docPrefix: "gallery", filename: "cat.jpg",
              filesize: 1234567, mimeType: "image/jpeg" }

Payload and S3
  -> return { docPrefix: "gallery", filename: "cat.jpg",
              url: "https://example-bucket.s3.amazonaws.com/gallery/cat.jpg?X-Amz-..." }

Admin browser
  -> PUT https://example-bucket.s3.amazonaws.com/gallery/cat.jpg?X-Amz-... with the original cat.jpg bytes
  -> POST https://cms.example.com/api/media
     _payload = {"alt":"A cat","prefix":"gallery"}
     file = { clientUploadContext: { prefix: "gallery" }, collectionSlug: "media",
              filename: "cat.jpg", mimeType: "image/jpeg", size: 1234567 }

Payload
  -> reads gallery/cat.jpg from S3, processes it, and creates the Media document

After This PR

Payload startup
  -> s3Storage({ clientUploads: true, collections: { media: true } })
  -> S3 provides uploadInstructions.generate
  -> Payload registers POST /api/upload-instructions
  -> client config exposes uploadInstructions = true for "media"

Admin page: user selects cat.jpg and saves
  -> Admin sees uploadInstructions = true
  -> POST https://cms.example.com/api/upload-instructions
     body = { collectionSlug: "media", docPrefix: "gallery", filename: "cat.jpg",
              filesize: 1234567, mimeType: "image/jpeg" }

Payload core
  -> checks access and file-size limits
  -> calls uploadInstructions.generate for "media"

S3
  -> returns { type: "http", filename: "cat.jpg",
               request: { method: "PUT", url: "https://example-bucket.s3.amazonaws.com/gallery/cat.jpg?X-Amz-...",
                          headers: { Content-Length: "1234567", Content-Type: "image/jpeg" } },
               uploadReference: { prefix: "gallery" } }

Admin browser
  -> PUT request.url with the original cat.jpg bytes and request.headers
  -> POST https://cms.example.com/api/media
     _payload = {"alt":"A cat","prefix":"gallery"}
     file = { uploadReference: { prefix: "gallery" }, collectionSlug: "media",
              filename: "cat.jpg", mimeType: "image/jpeg", size: 1234567 }

Payload
  -> reads gallery/cat.jpg from S3, processes it, and creates the Media document

The difference is only how the upload starts. Before, Admin used an S3 endpoint and S3 handler. Now, it asks Payload for upload instructions through one shared endpoint. The S3 upload and document request stay the same.

Other Storage Adapters

Some providers need their own SDK or multipart flow. They return a named dispatch instruction for the matching Admin helper:

R2
  -> { type: "dispatch", name: "uploadToR2" }
  -> R2 helper uses the existing multipart binding route

Vercel Blob
  -> { type: "dispatch", name: "uploadToVercelBlob", data: { pathname, token } }
  -> Vercel Blob helper uploads the bytes directly with put(...)

UploadThing
  -> { type: "dispatch", name: "uploadToUploadThing" }
  -> UploadThing helper runs its existing SDK flow

MCP

Standard instructions also make large MCP uploads possible (separate PR) without copying the file into a tool call as base64:

type = "http"
  -> send the local file using request.url, method, and headers

type = "dispatch"
  -> call the MCP tool with the same name
  -> return an unsupported-upload error when that tool is unavailable

This PR only defines the shared contract. A follow-up will let MCP follow the instructions and then call createDocument or updateDocument.

Current Scope

For now, the endpoint is added only when a collection provides uploadInstructions. Local storage and adapters without direct uploads will be supported next.

Breaking Changes

Normal storage adapter configuration does not need to change, and the clientUploads option is unchanged.

Code that directly calls the old S3, Azure, or GCS signing endpoints must use /api/upload-instructions and follow the returned request. The old adapter client component exports and setUploadHandler API are also removed. Custom client upload handlers must use a named dispatch instruction instead.

Upload instructions now return a complete file value for document creation. The old clientUploadContext property, its redundant handleUpload argument, and the duplicate collectionSlug are removed. The presence of uploadReference tells Payload that the file is already in storage and gives the adapter any data it needs to find it.

The ClientUploadsAccess type is removed from @payloadcms/plugin-cloud-storage/types. Use UploadInstructionsAccess from payload instead. The v4 migration guide includes detailed examples for each change.

Next Steps

1. Support every upload collection

Payload will use direct provider instructions when available and Payload-managed temporary storage otherwise. The same endpoint will then work for every upload collection.

2. Add MCP upload support

The MCP plugin will follow the same instructions, then pass the completed upload to createDocument or updateDocument instead of sending inline base64.

@github-actions

github-actions Bot commented Jul 13, 2026 •

Copy link
Copy Markdown
Contributor

📦 esbuild Bundle Analysis for payload

This analysis was generated by esbuild-bundle-analyzer. 🤖

Meta File Out File Size (raw) Note
packages/next/meta_index.json esbuild/index.js 201.89 KB ✅ No change
packages/payload/meta_index.json esbuild/index.js 1.41 MB ⚠️ +1.35 KB (+0.1%)
packages/payload/meta_shared.json esbuild/exports/shared.js 213.22 KB ⚠️ +122 B (+0.1%)
packages/richtext-lexical/meta_client.json esbuild/exports/client_optimized/index.js 285.56 KB ✅ No change
packages/ui/meta_client.json esbuild/exports/client_optimized/index.js 36.16 KB ✅ No change
packages/ui/meta_shared.json esbuild/exports/shared_optimized/index.js 18.95 KB ⚠️ +305 B (+1.6%)
Largest paths These visualization shows top 20 largest paths in the bundle.

Meta file: packages/next/meta_index.json, Out file: esbuild/index.js

Path Size
../../node_modules ${{\color{Goldenrod}{ ████████████████████████▋ }}}$ 98.9%, 197.86 KB
dist/adapters/router.js ${{\color{Goldenrod}{ }}}$ 0.4%, 718 B
dist/adapters/server.js ${{\color{Goldenrod}{ }}}$ 0.3%, 533 B
dist/adapters/layout.js ${{\color{Goldenrod}{ }}}$ 0.3%, 526 B
dist/adapters/views.js ${{\color{Goldenrod}{ }}}$ 0.2%, 409 B
dist/esbuildEntry.js ${{\color{Goldenrod}{ }}}$ 0.0%, 0 B

Meta file: packages/payload/meta_index.json, Out file: esbuild/index.js

Path Size
../../node_modules ${{\color{Goldenrod}{ █████████████████▎ }}}$ 69.0%, 964.28 KB
dist/fields/hooks ${{\color{Goldenrod}{ ▊ }}}$ 3.2%, 44.37 KB
dist/collections/operations ${{\color{Goldenrod}{ ▊ }}}$ 3.1%, 42.69 KB
dist/utilities/configToJSONSchema.js ${{\color{Goldenrod}{ ▎ }}}$ 1.1%, 15.99 KB
dist/auth/operations ${{\color{Goldenrod}{ ▎ }}}$ 1.1%, 15.69 KB
dist/fields/config ${{\color{Goldenrod}{ ▎ }}}$ 1.0%, 13.79 KB
dist/globals/operations ${{\color{Goldenrod}{ ▎ }}}$ 1.0%, 13.36 KB
dist/queues/operations ${{\color{Goldenrod}{ ▏ }}}$ 0.9%, 12.63 KB
dist/fields/validations.js ${{\color{Goldenrod}{ ▏ }}}$ 0.8%, 10.73 KB
dist/bin/generateImportMap ${{\color{Goldenrod}{ ▏ }}}$ 0.7%, 9.84 KB
dist/collections/config ${{\color{Goldenrod}{ ▏ }}}$ 0.7%, 9.33 KB
dist/config/orderable ${{\color{Goldenrod}{ ▏ }}}$ 0.6%, 8.07 KB
dist/index.js ${{\color{Goldenrod}{ ▏ }}}$ 0.6%, 7.96 KB
dist/uploads/fetchAPI-multipart ${{\color{Goldenrod}{ ▏ }}}$ 0.6%, 7.84 KB
dist/hierarchy/utils ${{\color{Goldenrod}{ ▏ }}}$ 0.5%, 7.64 KB
dist/database/migrations ${{\color{Goldenrod}{ ▏ }}}$ 0.5%, 7.55 KB
dist/config/sanitize.js ${{\color{Goldenrod}{ ▏ }}}$ 0.5%, 7.01 KB
dist/collections/endpoints ${{\color{Goldenrod}{ }}}$ 0.4%, 6.12 KB
dist/queues/config ${{\color{Goldenrod}{ }}}$ 0.4%, 5.59 KB
dist/utilities/telemetry ${{\color{Goldenrod}{ }}}$ 0.4%, 5.43 KB
(other) ${{\color{Goldenrod}{ ███████▊ }}}$ 31.0%, 433.31 KB

Meta file: packages/payload/meta_shared.json, Out file: esbuild/exports/shared.js

Path Size
../../node_modules ${{\color{Goldenrod}{ █████████████████▉ }}}$ 71.9%, 150.13 KB
dist/fields/validations.js ${{\color{Goldenrod}{ █▎ }}}$ 5.1%, 10.73 KB
dist/fields/config ${{\color{Goldenrod}{ ▋ }}}$ 2.8%, 5.82 KB
dist/utilities/traverseFields.js ${{\color{Goldenrod}{ ▌ }}}$ 2.1%, 4.44 KB
dist/collections/config ${{\color{Goldenrod}{ ▍ }}}$ 1.6%, 3.34 KB
dist/config/orderable ${{\color{Goldenrod}{ ▍ }}}$ 1.5%, 3.13 KB
dist/fields/baseFields ${{\color{Goldenrod}{ ▎ }}}$ 1.3%, 2.79 KB
dist/utilities/deepCopyObject.js ${{\color{Goldenrod}{ ▎ }}}$ 1.3%, 2.69 KB
dist/config/client.js ${{\color{Goldenrod}{ ▎ }}}$ 1.3%, 2.68 KB
dist/auth/cookies.js ${{\color{Goldenrod}{ ▏ }}}$ 0.7%, 1.55 KB
dist/utilities/flattenTopLevelFields.js ${{\color{Goldenrod}{ ▏ }}}$ 0.7%, 1.41 KB
dist/utilities/getVersionsConfig.js ${{\color{Goldenrod}{ ▏ }}}$ 0.5%, 1.04 KB
dist/globals/config ${{\color{Goldenrod}{ }}}$ 0.4%, 939 B
dist/utilities/flattenAllFields.js ${{\color{Goldenrod}{ }}}$ 0.4%, 793 B
dist/utilities/unflatten.js ${{\color{Goldenrod}{ }}}$ 0.4%, 779 B
dist/utilities/sanitizeUserDataForEmail.js ${{\color{Goldenrod}{ }}}$ 0.3%, 713 B
dist/auth/extractJWT.js ${{\color{Goldenrod}{ }}}$ 0.3%, 696 B
dist/utilities/getFieldPermissions.js ${{\color{Goldenrod}{ }}}$ 0.3%, 651 B
dist/errors/ValidationError.js ${{\color{Goldenrod}{ }}}$ 0.3%, 577 B
dist/bin/generateImportMap ${{\color{Goldenrod}{ }}}$ 0.3%, 561 B
(other) ${{\color{Goldenrod}{ ███████ }}}$ 28.1%, 58.62 KB

Meta file: packages/richtext-lexical/meta_client.json, Out file: esbuild/exports/client_optimized/index.js

Path Size
dist/features/blocks ${{\color{Goldenrod}{ ███▎ }}}$ 13.2%, 37.20 KB
dist/lexical/ui ${{\color{Goldenrod}{ ███ }}}$ 12.1%, 34.16 KB
dist/lexical/plugins ${{\color{Goldenrod}{ ██▉ }}}$ 11.8%, 33.18 KB
dist/features/experimental_table ${{\color{Goldenrod}{ ██▍ }}}$ 9.6%, 27.22 KB
dist/features/link ${{\color{Goldenrod}{ █▋ }}}$ 6.7%, 18.82 KB
dist/features/toolbars ${{\color{Goldenrod}{ █▍ }}}$ 5.9%, 16.58 KB
dist/features/upload ${{\color{Goldenrod}{ █▎ }}}$ 5.0%, 14.09 KB
dist/features/textState ${{\color{Goldenrod}{ ▉ }}}$ 3.9%, 11.08 KB
dist/lexical/utils ${{\color{Goldenrod}{ ▉ }}}$ 3.5%, 10.02 KB
dist/features/relationship ${{\color{Goldenrod}{ ▊ }}}$ 3.4%, 9.61 KB
dist/features/converters ${{\color{Goldenrod}{ ▊ }}}$ 3.0%, 8.36 KB
dist/utilities/fieldsDrawer ${{\color{Goldenrod}{ ▋ }}}$ 2.9%, 8.12 KB
dist/features/debug ${{\color{Goldenrod}{ ▋ }}}$ 2.6%, 7.40 KB
dist/lexical/config ${{\color{Goldenrod}{ ▍ }}}$ 1.8%, 5.14 KB
dist/features/lists ${{\color{Goldenrod}{ ▎ }}}$ 1.3%, 3.64 KB
dist/features/format ${{\color{Goldenrod}{ ▎ }}}$ 1.2%, 3.28 KB
dist/lexical/LexicalEditor.js ${{\color{Goldenrod}{ ▎ }}}$ 1.1%, 3.23 KB
dist/features/horizontalRule ${{\color{Goldenrod}{ ▎ }}}$ 1.1%, 3.18 KB
dist/field/Field.js ${{\color{Goldenrod}{ ▎ }}}$ 1.0%, 2.88 KB
dist/lexical/nodes ${{\color{Goldenrod}{ ▏ }}}$ 0.9%, 2.66 KB
(other) ${{\color{Goldenrod}{ █████████████████████▋ }}}$ 86.8%, 245.15 KB

Meta file: packages/ui/meta_client.json, Out file: esbuild/exports/client_optimized/index.js

Path Size
dist/exports/client ${{\color{Goldenrod}{ █████████████████████████ }}}$ 100.0%, 26.63 KB

Meta file: packages/ui/meta_shared.json, Out file: esbuild/exports/shared_optimized/index.js

Path Size
dist/graphics/Logo ${{\color{Goldenrod}{ ███████▋ }}}$ 30.5%, 5.57 KB
../../node_modules ${{\color{Goldenrod}{ ███▌ }}}$ 14.5%, 2.65 KB
dist/graphics/Icon ${{\color{Goldenrod}{ ██ }}}$ 8.3%, 1.51 KB
dist/utilities/formatDocTitle ${{\color{Goldenrod}{ █▊ }}}$ 7.2%, 1.32 KB
dist/providers/TableColumns ${{\color{Goldenrod}{ █▏ }}}$ 4.7%, 866 B
dist/utilities/getGlobalData.js ${{\color{Goldenrod}{ █ }}}$ 4.2%, 762 B
dist/utilities/api.js ${{\color{Goldenrod}{ █ }}}$ 4.1%, 756 B
dist/utilities/groupNavItems.js ${{\color{Goldenrod}{ █ }}}$ 4.1%, 745 B
dist/elements/Translation ${{\color{Goldenrod}{ ▋ }}}$ 2.7%, 493 B
dist/utilities/handleTakeOver.js ${{\color{Goldenrod}{ ▌ }}}$ 2.4%, 440 B
dist/utilities/traverseForLocalizedFields.js ${{\color{Goldenrod}{ ▌ }}}$ 2.3%, 419 B
dist/elements/withMergedProps ${{\color{Goldenrod}{ ▍ }}}$ 1.9%, 339 B
dist/utilities/getNavGroups.js ${{\color{Goldenrod}{ ▍ }}}$ 1.9%, 338 B
dist/utilities/getVisibleEntities.js ${{\color{Goldenrod}{ ▍ }}}$ 1.8%, 329 B
dist/elements/WithServerSideProps ${{\color{Goldenrod}{ ▎ }}}$ 1.3%, 232 B
dist/layouts/Root ${{\color{Goldenrod}{ ▎ }}}$ 1.3%, 230 B
dist/utilities/handleGoBack.js ${{\color{Goldenrod}{ ▎ }}}$ 1.0%, 180 B
dist/fields/mergeFieldStyles.js ${{\color{Goldenrod}{ ▏ }}}$ 0.9%, 158 B
dist/forms/Form ${{\color{Goldenrod}{ ▏ }}}$ 0.8%, 152 B
dist/utilities/handleBackToDashboard.js ${{\color{Goldenrod}{ ▏ }}}$ 0.8%, 152 B
(other) ${{\color{Goldenrod}{ █████████████████▍ }}}$ 69.5%, 12.68 KB
Details

Next to the size is how much the size has increased or decreased compared with the base branch of this PR.

  • ‼️: Size increased by 20% or more. Special attention should be given to this.
  • ⚠️: Size increased in acceptable range (lower than 20%).
  • ✅: No change or even downsized.
  • 🗑️: The out file is deleted: not found in base branch.
  • 🆕: The out file is newly found: will be added to base branch.

}

// 3. Create document in Payload (file already in storage)
const docResponse = await fetch(`/api/${collectionSlug}`, {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This old example was actually incorrect. Without sending clientUploadContext payload would not be able to match the document creation with the file previously uploaded


type ClientUploadConfig = {
/** Whether this collection provides separate upload instructions. */
uploadInstructions?: true

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what the admin panel reads to know whether it should just upload the file normally through payload, or fetch upload instructions to upload the file directly to the storage provider

({ upload }) => typeof upload === 'object' && upload.uploadInstructions,
)
) {
config.endpoints.push(uploadInstructionsEndpoint)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously, every single storage provider pushed their own endpoint for this. Now, we push one generic, standardized endpoint. The storage provider just sets upload.uploadInstructions

Comment thread packages/payload/src/types/index.ts Outdated
* Context of the file when it was uploaded via client side.
*/
clientUploadContext?: unknown
directUpload?: unknown

@AlessioGr AlessioGr Jul 14, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously, you had to pass the following to POST /api/<collectionslug> after the direct upload is done:

"clientUploadContext": {
    "prefix": "gallery"
  }

Now:

uploadReference: { prefix: 'gallery' },

This is what tells Payload

  1. the file is not provided here, it was uploaded directly before
  2. this is where I can find the file (in this case, prefix - varies by provider, hence unknown)

} & (
| {
data?: unknown
name: string

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For azure (multipart upload), and vercel/uploadthing (upload through their client sdk).


const bytesToMB = (bytes: number) => bytes / 1024 / 1024

export const uploadInstructionsEndpoint: Endpoint = {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New generic endpoint to fetch upload instructions, such as which signed URL to upload to. Replaces the adapter-specific handlers in:

storage-s3/src/generateSignedURL.ts
storage-azure/src/generateSignedURL.ts
storage-gcs/src/generateSignedURL.ts
storage-vercel-blob/src/getClientUploadRoute.ts


const { access, generate } = uploadInstructions
if (
access ? !(await access({ collectionSlug: uploadRequest.collectionSlug, req })) : !req.user

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not new. Previously, the adapter-specific handlers just called the access control directly, since they owned it.

Now that payload owns it: the adapters pass the access control to the new collection?.config?.upload.uploadInstructions?.access property, payload then reads it

withMetadata?: WithMetadata
}

export type UploadInstructionsAccess = (args: {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not new. Previously, the adapter-specific handlers just called the access control directly, since they owned it.

Now that payload owns it: the adapters pass the access control to the new collection?.config?.upload.uploadInstructions?.access property, payload then reads it

Comment thread packages/payload/src/uploads/types.ts Outdated

export type UploadInstructionsCapability = {
/** Controls access to generating upload instructions. */
access?: UploadInstructionsAccess

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is payload-owned, adapters now provide these to payload, which reads them in the generic upload instruction handler.

Regarding upload instructions: generate signed url = generate upload instructions. Same thing, different teminology. "signed url" would not be accurate, since that's not what azure, vercel blob and uploadthing returns.

serverURL: string
updateFilename: (value: string) => void
}) => Promise<unknown>
name: string

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If upload instructions are of type dispatch and not http, the name they return is matched to the listener created through here.

tempFilePath?: string
}

export type ClientUploadsAccess = (args: {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved into payload package

import { createClientUploadHandler } from '@payloadcms/plugin-cloud-storage/client'
import { formatAdminURL } from 'payload/shared'

export const AzureClientUploadHandler = createClientUploadHandler({

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed because Azure now uses the shared upload flow. Generic client handling moved to our shared packages/ui/src/providers/UploadHandlers/index.tsx, while Azure-specific upload instructions remain in packages/storage-azure/src/generateUploadInstructions.ts.

useCompositePrefixes?: boolean
}

export const generateUploadInstructions = ({

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed from generateSignedURL

body: await createFormData(
form.formState,
overrides,
collectionSlug,

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed - can be inferred from URL, so this was unnecessary

const instructions = (await response.json()) as UploadInstructions
let uploadedFile = instructions.file

if (instructions.type === 'http') {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shared generic handler for http upload instructions. Previously, each storage adapter needed to provide their own handler client component that does this

}

const result = await new Promise<unknown>((resolve, reject) => {
const event = new CustomEvent(`payload:upload:${instructions.name}`, {

@AlessioGr AlessioGr Jul 14, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, type = dispatch.
=> same behavior as before: call client handler provided by the storage adapter.

Only difference: instead of getting the handler through uploadHandlers.get(, we broadcast an event that the storage adapter listens to.

We need to declare this as a generic dispatch instruction, because this is no longer just consumed by the admin panel. In MCP, we will treat dispatch instructions as "call external mcp tool"

@AlessioGr
AlessioGr marked this pull request as ready for review July 14, 2026 02:28
Comment thread docs/migration-guide/v4.mdx Resolved
@paulpopus

Copy link
Copy Markdown
Member

Confirmed critical bug: packages/payload/src/uploads/endpoints/uploadInstructions.ts:30 — collection?.config?.upload.uploadInstructions stops the optional chain before .upload, so any request naming a non-upload-enabled collection throws an unhandled TypeError (500) pre-auth instead of the intended 400. I verified this directly by reading the file — one-character fix (upload.uploadInstructions → upload?.uploadInstructions).

# Conflicts:
#	docs/migration-guide/v4.mdx
#	docs/upload/storage-adapters.mdx
#	packages/storage-uploadthing/README.md
#	packages/storage-uploadthing/src/adapter.ts
#	packages/storage-uploadthing/src/client/UploadthingClientUploadHandler.ts
#	packages/storage-uploadthing/src/getClientUploadRoute.ts
#	packages/storage-uploadthing/src/getFile.ts
#	packages/storage-uploadthing/src/index.ts
#	packages/storage-uploadthing/src/uploadFile.ts
@AlessioGr
AlessioGr requested a review from paulpopus July 15, 2026 17:25
@AlessioGr
AlessioGr disabled auto-merge July 15, 2026 17:30
@AlessioGr
AlessioGr enabled auto-merge (squash) July 15, 2026 17:30
type: 'dispatch',
data: {
pathname: resolved.fileKey,
token: await generateClientTokenFromReadWriteToken({

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The deleted getClientUploadRoute.ts wrapped the equivalent token-generation call in try/catch and logged unexpected errors via req.payload.logger.error(error) before rethrowing. This inline generate() has no surrounding try/catch, so a generateClientTokenFromReadWriteToken failure (bad credentials, Vercel API outage) now only surfaces to the client with no corresponding server-side log entry.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have routeError.ts which catches all errors and logs them

Comment thread docs/migration-guide/v4.mdx Resolved
Comment thread docs/migration-guide/v4.mdx Outdated

If you only configure a storage adapter with `clientUploads: true`, no migration is needed. The Admin Panel uses the new endpoint automatically.

`upload.limits.fileSize` is now checked before Payload returns upload instructions. This is new for Azure, GCS, R2, and Vercel Blob; S3 already enforced this limit. If these client uploads previously exceeded the server limit, increase `upload.limits.fileSize` or Payload will reject them before the upload begins.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fileSize check looks to only exist in the s3 adapter, not the others. This is something that we should be doing, though. We should either update this to reflect current state or leave it and file an issue/task to update the other adapters with this check.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already are up-to-date! Previous state: only S3 enforced this limit. Now: all adapters enforce this limit through shared endpoint.

This is new for Azure, GCS, R2, and Vercel Blob; S3 already enforced this limit.

@AlessioGr
AlessioGr requested a review from denolfe July 16, 2026 19:32
denolfe
denolfe previously approved these changes Jul 16, 2026
@AlessioGr
AlessioGr merged commit 6981aca into main Jul 16, 2026
340 of 342 checks passed
@AlessioGr
AlessioGr deleted the refactor/client-uploads branch July 16, 2026 23:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants