formie icon indicating copy to clipboard operation
formie copied to clipboard

Support Direct File Uploads to Craft Cloud for Large Attachments

Open shennyg opened this issue 11 months ago • 8 comments

What are you trying to do?

Follow up on #2114. I'd love to see the option to have attachments directly upload to Craft Cloud / S3 allowing Craft Cloud hosted sites to accept forms with larger than 6MB files.

For front-end uploads there is a solution to bypass Lambda and instead send data to S3 (not limited by the 6MB limit), but it would require a slightly different approach. In the context of Formie, the file upload/front end uploading would be the area. The Craft team have said they plan to provide documentation on being able to implement the Craft Cloud S3 upload method, similar to how to the Craft Cloud filesystem type works, that allows for larger uploads without restrictions. I believe developers are being offered sandboxes for testing on Craft Cloud, if it is something you are interested in or if you wanted to have Formie verified on Craft Cloud through the additional verification program, that is possible:

https://github.com/verbb/formie/issues/2114#issuecomment-2463790715

What's your proposed solution?

Request a pre-signed URL once a file is selected to enable direct uploads to Craft Cloud. I imagine you can use what Craft Cloud uses, see https://github.com/craftcms/cloud-extension-yii2/blob/2.x/src/controllers/AssetsController.php#L27-L87

An example JS request:

fetch("/admin/actions/cloud/assets/get-upload-url", {
  "headers": {
    "accept": "application/json, text/plain, */*",
    "content-type": "application/json",
    "pragma": "no-cache",
    "sec-fetch-dest": "empty",
    "sec-fetch-mode": "cors",
    "sec-fetch-site": "same-origin",
    "x-csrf-token": "",
    "x-registered-asset-bundles": "",
    "x-registered-js-files": "",
    "x-requested-with": "XMLHttpRequest"
  },
  "referrer": "/admin/assets?source=volume%3Afe8db2fe-b02f-479e-aaf4-f21ed7f72725",
  "referrerPolicy": "origin-when-cross-origin",
  "body": "{\"folderId\":3,\"CRAFT_CSRF_TOKEN\":\"",\"filename\":\"sample2.pdf\"}",
  "method": "POST",
  "mode": "cors",
  "credentials": "include"
});

Or take a look at what JS Craft Cloud uses: https://github.com/craftcms/cloud-extension-yii2/blob/2.x/src/web/assets/uploader/src/Uploader.js#L118

Looks like you need to post the filename, CSRF token and maybe folderId.

You are returned a AWS URL to post the file to and it is saved to S3.

Attach the file key / URL to the form submission after the upload completes and you can then link from the form submission to the attachment.

References

Thanks!

Additional context

No response

shennyg avatar Mar 06 '25 23:03 shennyg

Ideally, we can generically expose this capability on the Craft FS level. That way, AWS-S3 filesystems as well as Cloud ones would work, and Formie (or the dev implementing the form) could check if the FS has presigned URL uploads, and if so, opt to use it.

timkelty avatar Mar 07 '25 00:03 timkelty

@timkelty Is there an open issue on craftcms/cms for this? I would subscribe to updates, it's something we're likely to need very soon.

daltonrooney avatar Apr 28 '25 22:04 daltonrooney

@daltonrooney No, but there is now: https://github.com/craftcms/cms/discussions/17195

Discussion was pretty fragmented across repos, issues, and discussions. Thanks for the nudge!

timkelty avatar Apr 29 '25 09:04 timkelty

Bringing this one back up, as it would be good if Formie's upload file had Craft Cloud support, given the 6 MB limit on uploads from the traditional web/POST method.

Similar to this, documentation about uploading via the asset layer and not the web layer would be beneficial and something highlighted already: https://github.com/craftcms/cloud/discussions/51

jamesmacwhite avatar Nov 03 '25 08:11 jamesmacwhite

Yeah, was kinda waiting for Craft itself to handle this so we can make use of that rather than roll our own.

engram-design avatar Nov 03 '25 09:11 engram-design

Yeah, was kinda waiting for Craft itself to handle this so we can make use of that rather than roll our own.

Thanks Josh, yes that would make the most sense. Between https://github.com/craftcms/cms/discussions/17195 and https://github.com/craftcms/cloud/discussions/51 there would ideally need be official documentation for it, so plugin development can take advantage.

At the moment, other then reverse engineering the way asset uploads are handled we don't have a lot of options currently, so Craft Cloud uploads are a bit limited.

jamesmacwhite avatar Nov 03 '25 09:11 jamesmacwhite

@jamesmacwhite @engram-design you're not the only ones waiting on this, I promise :)

Trying to make this a priority in the coming week, as we've been promising it for far to long. Stay tuned!

timkelty avatar Nov 03 '25 13:11 timkelty

Amazing! Thanks for the update @timkelty

jamesmacwhite avatar Nov 03 '25 17:11 jamesmacwhite