Skip to content

Issue direct upload URLs from Cloud filesystems - #216

Open
brandonkelly wants to merge 5 commits into
3.xfrom
direct-upload-urls
Open

brandonkelly wants to merge 5 commits into
3.xfrom
direct-upload-urls

Conversation

@brandonkelly

@brandonkelly brandonkelly commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

Description

Craft 5.13 is adding core upload sessions, so the control panel, front-end forms and MCP can upload files straight to storage. That gets around Lambda's 6 MB request limit. A filesystem opts in by implementing craft\base\TemporaryUploadUrlInterface, and this PR implements it for Cloud's filesystems.

  • Fs::temporaryUploadUrl($path, $expiresAt, $options) returns a presigned S3 PutObject URL, plus the headers the client must send: every signed header except host. It returns null under useLocalFs, so Craft falls back to its own transfer endpoint.
  • It signs Content-Type and Content-Length, from Craft's ContentType and ContentLength options. The AWS SDK leaves both unsigned by default, which would let a client upload any size, or store HTML under a .jpg name that the CDN then serves as HTML. Upload URLs use a separate client whose signer covers both headers, so S3 rejects a mismatched request with a 403. Other presigned URLs aren't affected. If a caller doesn't pass a type, the type for the path's extension is signed.
  • Craft moves the uploaded file into place with renameFile(). That copies the object's metadata, so the type and visibility set on the upload are what the CDN serves.
  • src/fs/TemporaryUploadUrlInterface.php shims the interface for Craft versions before 5.13, the same way ReleasableQueueInterface does.

This has no effect until the Craft side ships. Cloud's own control panel uploader (cloud/assets/* and Uploader.js) stays in place for older Craft versions, and will be removed once Cloud requires a Craft version that includes upload sessions.

Related issues

Copilot AI balanced review requested due to automatic review settings November 12, 2026 12:45

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Compatibility and the MCP upload/claim flow still require validation against the upstream DirectUploadFsInterface, which is unavailable on Craft’s 5.x branch; the reported stub does not establish that contract.

No open issues 🎉

What changed in this PR

Adds direct S3 upload URLs to Cloud filesystems so Craft’s MCP uploads can bypass Lambda’s 6 MB request limit, while retaining the local-filesystem fallback.

Changes:

  • Implements direct-upload support with URLs and required headers derived from a shared presigned request.
  • Adds an interface shim for compatibility with older Craft versions.
  • Adds unit tests for temporary-upload paths, signed metadata headers, and local-filesystem fallback.
File Description
tests/​unit/​FsTest.php Tests direct-upload URLs, required headers, and local fallback.
src/​fs/​Fs.php Implements direct-upload URL generation and shares presigning logic.
src/​fs/​DirectUploadFsInterface.php Adds a compatibility shim for Craft’s direct-upload interface.

Review effort: Balanced

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are reported for the direct S3 upload changes.

No open issues 🎉

Review effort: Balanced

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Needs a closer look

The unpublished Craft 5.13 upload-session contract requires human compatibility confirmation and end-to-end S3 validation that signed type/size mismatches are rejected and metadata survives finalization.

No open issues 🎉

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 17, 2026 11:11

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Human assessment is needed because upload-client initialization failures can escape exception handling and bypass the documented null fallback.

No open issues 🎉

Review effort: Balanced

brandonkelly and others added 4 commits December 1, 2026 11:57
Implement Craft's DirectUploadFsInterface (5.12.2+) on Fs, so Craft's MCP
server can send files straight to S3 instead of through Lambda's 6 MB
request limit. The interface is shimmed for older Craft versions.

Amp-Thread-ID: https://ampcode.com/threads/T-54e734d2-d69f-42d7-9f3b-a6a8e281ad1d
Co-authored-by: Amp <amp@ampcode.com>
Rename getDirectUploadUrl() to temporaryUploadUrl() to match Craft 5.13's
interface, and sign Content-Type and Content-Length so storage rejects
uploads of another type or size. The SDK leaves both unsigned by default.

Amp-Thread-ID: https://ampcode.com/threads/T-01a1e63f-d13c-70f3-bc1e-77416ea26a1e
Co-authored-by: Amp <amp@ampcode.com>
- Name the object the way Flysystem does, so paths that need encoding
  aren't stored under a different key than Craft reads and deletes.
- Return null when the URL can't be signed, so Craft falls back to
  receiving the file itself.
- Only replace the SDK's signer for SigV4; other versions use the SDK's.
- Ignore test logs.

Amp-Thread-ID: https://ampcode.com/threads/T-01a1e63f-d13c-70f3-bc1e-77416ea26a1e
Co-authored-by: Amp <amp@ampcode.com>
Copilot AI balanced review requested due to automatic review settings December 1, 2026 11:58

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

S3 client initialization exceptions can escape the existing wrapper, aborting upload-session creation instead of returning null for Craft’s transfer fallback.

1 open issue

Review effort: Balanced

Comment thread src/fs/Fs.php Resolved
Creating the upload client happened outside the try block, so a failure
there escaped instead of returning null for Craft's transfer fallback.

Amp-Thread-ID: https://ampcode.com/threads/T-01a1e63f-d13c-70f3-bc1e-77416ea26a1e
Co-authored-by: Amp <amp@ampcode.com>
Copilot AI balanced review requested due to automatic review settings December 1, 2026 12:04

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

The direct-to-S3 upload changes have no active review issues.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants