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

[6.0] Media: fix large file upload by using of binary upload instead of base64, and display correct upload progress #44848

Open
wants to merge 51 commits into
base: 6.0-dev
Choose a base branch
from

Conversation

Fedik
Copy link
Member

@Fedik Fedik commented Feb 10, 2025

Summary of Changes

The PR changes the media manager to use FormData for file upload, instead of base64 payload.
Which improves responsiveness, performance and handling of large files in general.

However the api/ calls still uses base64 because it is hard to do in b/c maner.

Bonus: the upload progres now showing actual upload progress.

Testing Instructions

Apply patch.
Run npm install.
Go to media manager and try upload something bigger than 100Mb

Addittionaly, test with any 3d filesystem plugin.

Actual result BEFORE applying this Pull Request

The browser hangs for a while, and dependent from your luck the upload will be completed after some waiting.

Expected result AFTER applying this Pull Request

The upload starts immediately, and you can see progress (a litle 5px blue line over the files list)

Link to documentations

Please select:

  • Documentation link for docs.joomla.org:
  • No documentation changes for docs.joomla.org needed
  • Pull Request link for manual.joomla.org: IDK
  • No documentation changes for manual.joomla.org needed

Sorry, something went wrong.

Fedik and others added 3 commits February 10, 2025 17:28

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
…ation-types.es6.js

Co-authored-by: Brian Teeman <brian@teeman.net>
cs
@Fedik Fedik changed the title [5.3] Media: fix large file upload with use of binary upload instead of base64, and display correct upload progress [5.3] Media: fix large file upload by using of binary upload instead of base64, and display correct upload progress Feb 10, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
@laoneo
Copy link
Member

laoneo commented Feb 11, 2025

I like that change, but this will break 3rd party extensions when the data can be all of the sudden a resource. I would read the file content it in the api controller and then pass it to the adapter the same way as before that no changes are needed in the adapter. Additionally, the check content logic can probably be moved to the, but not sure about this.

@richard67
Copy link
Member

Additionally, the check content logic can probably be moved to the, but not sure about this.

@laoneo Moved to the ... what?

@laoneo
Copy link
Member

laoneo commented Feb 11, 2025

ApiController

@Fedik
Copy link
Member Author

Fedik commented Feb 11, 2025

Hmhm,

I would read the file content it in the api controller and then pass it to the adapter the same way as before that no changes are needed in the adapter

No no, this not going to work, you will get "out of memory" error when try to read 100Mb file when PHP limit is 60Mb.
This will bring back problem with large file upload.
Loading whole file in to memory should never happen while uploading (unless when it realy need).

What about stringable object?
We wrap uploaded file in to that object, and the file will be loaded in to memory only when the plugin expecting a string. Addittionaly we deprecate this behavior.
What do you think?

@laoneo
Copy link
Member

laoneo commented Feb 11, 2025

Not sure if stringable would solve it. But I think the main goal should be to do it in a bc way.

@Fedik
Copy link
Member Author

Fedik commented Feb 11, 2025

I updated the code to use stringable object.
In my tests it works well even when try to access the data as to the string.

Would be good to have some more test, to be sure, with 3rd filesystem adapters.

Fedik and others added 4 commits February 11, 2025 15:05

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
joomdonation and others added 24 commits February 26, 2025 19:15

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
* Change list() to array destruct for libraries code

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
…oomla#44970)

* Change list() to array destruct for modules and plugins code

---------

Co-authored-by: Quy Ton <quy@nomonkeybiz.com>

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
* Add deprecation message to content modules

---------

Co-authored-by: Quy <quy@nomonkeybiz.com>

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
Co-authored-by: Richard Fath <richard67@users.noreply.github.com>

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
The `CYPRESS_CACHE_FOLDER` environment variable must be set within the `sudo` command.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
* [Cypress] PHP Backend Notice com_media/Files.cy.js

Fixing all Joomla backend PHP notices from Cypress test file `api/com_media/Files.cy.js` and doing some refactoring.

Fixed PHP notices are:
```
[Sat Feb 22 18:28:44.019593 2025] [php:notice] [pid 31:tid 31] [client 10.0.0.1:64714] PHP Notice:  exif_imagetype(): Error reading from /var/www/html/files/test-image-1.jpg! in /var/www/html/libraries/src/Helper/MediaHelper.php on line 93
[Sat Feb 22 18:28:44.022074 2025] [php:notice] [pid 31:tid 31] [client 10.0.0.1:64714] PHP Notice:  getimagesize(): Error reading from /var/www/html/files/test-image-1.jpg! in /var/www/html/libraries/src/Image/Image.php on line 177
[Sat Feb 22 18:28:44.258619 2025] [php:notice] [pid 31:tid 31] [client 10.0.0.1:64714] PHP Notice:  exif_imagetype(): Error reading from /var/www/html/files/test-dir/test-image-1-subfolder.jpg! in /var/www/html/libraries/src/Helper/MediaHelper.php on line 93
[Sat Feb 22 18:28:44.259092 2025] [php:notice] [pid 31:tid 31] [client 10.0.0.1:64714] PHP Notice:  getimagesize(): Error reading from /var/www/html/files/test-dir/test-image-1-subfolder.jpg! in /var/www/html/libraries/src/Image/Image.php on line 177
[Sat Feb 22 18:28:47.177357 2025] [php:notice] [pid 31:tid 31] [client 10.0.0.1:64714] PHP Notice:  exif_imagetype(): Error reading from /var/www/html/files/test-dir/todelete.jpg! in /var/www/html/libraries/src/Helper/MediaHelper.php on line 93
[Sat Feb 22 18:28:47.178099 2025] [php:notice] [pid 31:tid 31] [client 10.0.0.1:64714] PHP Notice:  getimagesize(): Error reading from /var/www/html/files/test-dir/todelete.jpg! in /var/www/html/libraries/src/Image/Image.php on line 177
[Sat Feb 22 18:28:47.564807 2025] [php:notice] [pid 31:tid 31] [client 10.0.0.1:64714] PHP Notice:  exif_imagetype(): Error reading from /var/www/html/images/test-dir/todelete.jpg! in /var/www/html/libraries/src/Helper/MediaHelper.php on line 93
[Sat Feb 22 18:28:47.565288 2025] [php:notice] [pid 31:tid 31] [client 10.0.0.1:64714] PHP Notice:  getimagesize(): Error reading from /var/www/html/images/test-dir/todelete.jpg! in /var/www/html/libraries/src/Image/Image.php on line 177
```

All 8 x PHP notices are fixed. Instead of using 1-Byte files real images are used from Cypress fixtures.
Please consider there are still 4 x PHP warning to be fixed (I assume they need to be fixed in PHP API backend code) from `api/com_media/Files.cy.js` and more warnings and notices in the overall Joomla System Tests.

Some refactoring:
* Deleted 3 images in `tests/System/data/com_media`, 2 are not used and Cypress default is to use `fixtures` folder
* The image file names are counted through and the images show name and path in different colors.
* Second `test-dir` was named `test-dir2` to distinguish clearly.
* `afterEach()` is reduced to `after()`, as it is only a clean-up and not needed to execute the tests.
* The last 4 tests can use the prepared files too, as with `beforeEach` the files are restored before each test.

* Corrected Image Description to test-dir2

Used command:
```
convert -size 100x100 -gravity center -pointsize 11 xc:lightgreen -fill red -annotate +0+0 'Joomla\nSystem Tests\n\nimages/test-dir2\ntest-image-3.jpg' tests/System/fixtures/com_media/test-image-3.jpg
```

* Fix for Windows Path and Read-Only Overwrites

- Creating relative fixtures folder path now also works on Windows with backslashes as separators and a drive letter
- All overwrite files are now created with explicit read-write 0o666, as the default 0o444 creates read-only files, leading to PHP Warnings `Failed to open`

---------

Co-authored-by: Allon Moritz <allon.moritz@digital-peak.com>
Co-authored-by: Robert Deutz <rdeutz@googlemail.com>

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
)

* Remove unsed variable

* fix as reuested

* Add a comment

---------

Co-authored-by: Allon Moritz <allon.moritz@digital-peak.com>
Co-authored-by: Benjamin Trenkle <bembelimen@users.noreply.github.com>

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
…2-28

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
 Conflicts:
	plugins/filesystem/local/src/Adapter/LocalAdapter.php
@HLeithner HLeithner changed the base branch from 5.3-dev to 6.0-dev March 4, 2025 17:18
@HLeithner HLeithner requested a review from rdeutz as a code owner March 4, 2025 17:18
@HLeithner
Copy link
Member

This pull request has been automatically rebased to 6.0-dev.

@HLeithner HLeithner changed the title [5.3] Media: fix large file upload by using of binary upload instead of base64, and display correct upload progress [6.0] Media: fix large file upload by using of binary upload instead of base64, and display correct upload progress Mar 4, 2025
@rdeutz rdeutz removed the PR-5.3-dev label Mar 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature NPM Resource Changed This Pull Request can't be tested by Patchtester Performance PR-6.0-dev
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Large file uploads (~1 GB+) do not start in Media Manager.