Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chunked file uploads #6421

Merged
merged 13 commits into from
Jun 28, 2024
Merged

Chunked file uploads #6421

merged 13 commits into from
Jun 28, 2024

Conversation

distantnative
Copy link
Member

@distantnative distantnative commented Apr 28, 2024

Description

Summary of changes

  • New Api\Upload class
    • Takes over all the nested code from Api\Api::upload() to make it more easily to read and test
    • Adds support for uploads in chunks

Reasoning

Changelog

Features

Enhancements

  • New uploadAsChunks JS helper function

Fixed

  • Canceling the file upload dialog now also cancels ongoing uploads

Refactored

  • New Kirby\\Api\Upload class to handle file uploads via the REST API

Ready?

  • In-code documentation (wherever needed)
  • Unit tests for fixed bug/feature
  • Tests and CI checks all pass

For review team

  • Add changes & docs to release notes draft in Notion

@afbora
Copy link
Member

afbora commented Apr 30, 2024

I've tried to upload a EXE file. Kirby 4.2.0 throws a error The extension "exe" is not allowed but nothing happens for this PR. Seems something broken.

@afbora
Copy link
Member

afbora commented Apr 30, 2024

Also I realized that file is still remains when I cancel the upload. Should be deleted. But should be careful when file replacing.

@distantnative
Copy link
Member Author

@afbora We cannot delete the tmp file on cancel. But we clean up the files with a garbage collection.

@distantnative distantnative force-pushed the feature/chunk-uploads branch from f3e3800 to f311c15 Compare May 1, 2024 16:46
@distantnative distantnative marked this pull request as ready for review May 2, 2024 09:57
@distantnative distantnative force-pushed the feature/chunk-uploads branch from f311c15 to 1372287 Compare May 2, 2024 09:57
src/Panel/Panel.php Outdated Show resolved Hide resolved
src/Api/Upload.php Outdated Show resolved Hide resolved
config/api/routes/files.php Outdated Show resolved Hide resolved
panel/src/helpers/upload.js Outdated Show resolved Hide resolved
src/Api/Upload.php Outdated Show resolved Hide resolved
src/Api/Upload.php Outdated Show resolved Hide resolved
src/Api/Upload.php Outdated Show resolved Hide resolved
src/Api/Upload.php Outdated Show resolved Hide resolved
config/api/routes/files.php Outdated Show resolved Hide resolved
@lukasbestle lukasbestle added the needs: two-person review 🧑‍🤝‍🧑 PR must only be merged with two approvals label May 2, 2024
@lukasbestle
Copy link
Member

Adding the "two-person review" label as I realized we need to be super careful about the security implications here. There's a lot that could go horribly wrong if we miss anything. I think we are heading in a great direction though 👍

@distantnative
Copy link
Member Author

@lukasbestle makes sense. And as written in the initial post, I think we should have a few review rounds as well. Now getting the concept right, later adding unit tests etc. before final review.

@afbora
Copy link
Member

afbora commented May 3, 2024

We cannot delete the tmp file on cancel. But we clean up the files with a garbage collection.

@distantnative What if we upload to the temp folder, does it make sense? If upload successful, we can move the file to the model root, if not garbage collector take care.

@distantnative
Copy link
Member Author

@afbora That's what we are doing here. Just not the system temp folder as that doesn't persist across requests. So the first parts aren't there anymore when the last chunk is received.

@tobimori
Copy link
Contributor

tobimori commented May 3, 2024

Is it theoretically possible to add a config option that will limit the file size?

@afbora
Copy link
Member

afbora commented May 3, 2024

I've found few issues, could you confirm that?

  • File not uploaded without error or log (dialog closed and no file uploaded,) with big files. For me, ~100 MB success, ~300 MB fails.
  • I'm getting A file with the name "filename.zip" already exists error when big files upload from textarea field

@distantnative
Copy link
Member Author

@afbora the PR currently is not functional as it's in the middle of implementing changes based on Lukas' feedback and some troubles I encountered (see our comments discussion). Sorry that you tried, but I think any upload fails currently that needs more than one chunk.

@afbora
Copy link
Member

afbora commented May 3, 2024

@distantnative No problem. I'll test again after PR is ready.

@lukasbestle
Copy link
Member

Is it theoretically possible to add a config option that will limit the file size?

Good point. I think it would make sense to make this an option for the file blueprint.

@distantnative
Copy link
Member Author

@lukasbestle @tobimori are you thinking of something different than the existing accept maxsize option?

@tobimori
Copy link
Contributor

tobimori commented May 5, 2024

I didn't know there was an option already. Consider my request as solved 😀

@lukasbestle
Copy link
Member

Also forgot about maxsize. 😆

@distantnative
Copy link
Member Author

@lukasbestle added some more validations – skipping MIME types (will still checked for the full file), but at least basic ones as allowed extensions.

src/Api/Upload.php Outdated Show resolved Hide resolved
@afbora
Copy link
Member

afbora commented Jun 27, 2024

Works great for me. I couldn't see any issue 🎉

@distantnative
Copy link
Member Author

I think I have encountered an issue: Uploading a large file and canceling while it's uploading, it still shows up in the file list after a reload.

@distantnative
Copy link
Member Author

Turns out: When one cancels the upload dialog, all running uploads still run and finish in the background. This is not new in this PR but a lot more visible/likely to happen with a different expectation by the user.

@distantnative
Copy link
Member Author

@lukasbestle @afbora Added a way to abort ongoing upload requests. Could you please review the last commit and test it out?

@afbora
Copy link
Member

afbora commented Jun 28, 2024

@distantnative Still works great for me 👍

@distantnative distantnative changed the base branch from develop-minor to v5/develop June 28, 2024 13:09
@distantnative distantnative modified the milestones: 4.4.0, 5.0.0-alpha.2 Jun 28, 2024
@distantnative distantnative force-pushed the feature/chunk-uploads branch from 81e51f2 to 56272f0 Compare June 28, 2024 13:09
Copy link
Member

@lukasbestle lukasbestle left a comment

Choose a reason for hiding this comment

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

Works great for me as well 👍

@distantnative distantnative merged commit 5c03948 into v5/develop Jun 28, 2024
7 checks passed
@distantnative distantnative deleted the feature/chunk-uploads branch June 28, 2024 19:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs: two-person review 🧑‍🤝‍🧑 PR must only be merged with two approvals
Development

Successfully merging this pull request may close these issues.

5 participants