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

[MODX 3] Media browser uploads file to incorrect path when media source is changed #16532

Open
halftrainedharry opened this issue Feb 23, 2024 · 3 comments
Labels
bug The issue in the code or project, which should be addressed.

Comments

@halftrainedharry
Copy link
Contributor

Bug report

Summary

Under certain conditions, the media browser uploads files to the wrong path after the media source is changed.

Step to reproduce

  • Create a media source. (For example "Images" with basePath/baseUrl = assets/images/.)
  • Create a static resource and select a file from the media browser that is located in a subfolder. (For example assets/images/blue.png.)

bug_media_browser_static_resource

  • Open the media browser again (to select a different file).
  • Change the media source. (For example to "Images".)
  • Click the "Upload Files" button and select a file.
  • Instead of the media source root folder (assets/images/), the file is uploaded to the directory assets/images/assets/images/.

bug_media_browser_wrong_path

Cause of the error

In the media browser code, when the media source is changed, the active node is set to an empty string: this.cm.activeNode = '';

,changeSource: function(sel) {
this.cm.activeNode = '';
var s = sel.getValue();
var rn = this.getRootNode();
if (rn) { rn.setText(sel.getRawValue()); }

Now when a file is uploaded and the active node is empty, the code uses the value of this.config.openTo for the path (which is set to the path of the file that was selected when the media browser was opened.)

,beforeUpload: function() {
var path = this.config.openTo || this.config.rootId || '/';
if (this.cm.activeNode) {

Possible solution

In the media browser code, after the media source is changed, set the active node to the root node of the media source.

var rn = this.getRootNode();
if (rn) { rn.setText(sel.getRawValue()); }

if (rn) { rn.setText(sel.getRawValue()); this.cm.activeNode = rn; }

Environment

MODX 3.0.4-pl.

@halftrainedharry halftrainedharry added the bug The issue in the code or project, which should be addressed. label Feb 23, 2024
@modxcommunity
Copy link
Collaborator

This issue has been mentioned on MODX Community. There might be relevant details there:

https://community.modx.com/t/binary-static-resources-not-downloading/7555/8

@smg6511
Copy link
Collaborator

smg6511 commented Mar 24, 2024

On 3.1.0-dev I'm not seeing this happening. Can you create a video capture of your process of reproducing the issue? Also, a screen grab of the media source setup would help as well.

@halftrainedharry
Copy link
Contributor Author

On 3.1.0-dev I'm not seeing this happening.

Yes, it looks like this issue is fixed in the current version that's under development.
It seems that with the PR #16394, when the media source is changed, the active node gets set again here in the code:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug The issue in the code or project, which should be addressed.
Projects
None yet
Development

No branches or pull requests

3 participants