October: storage path with double app sub folder segment eg: appfolder/appfolder/storage

Created on 16 Jan 2019  路  13Comments  路  Source: octobercms/october

  • OctoberCMS Build: 1.0.446
  • PHP Version: 7.2.11
  • Database Engine: mysql
  • Plugins Installed: default

I can upload file and success, but the url link return invalid url with double app sub folder segment
eg : http://site.com/appfolder/appfolder/storage/.../.../file.jpg

Completed Bug

All 13 comments

temporary fixed, by adding my sub folder on MediaLibrary classes init

    **$this->storagePath = rtrim(Config::get('cms.storage.media.path', 'appfolder/storage/app/media'), '/');**

Duplicate: https://github.com/octobercms/october/issues/4039
PR Fix: https://github.com/octobercms/october/pull/4055

If it's still not fixing your bug, ping me on this ticket.

@w20k PR Fix: #4055 not work for me,

{
        $path = $this->validatePath($path);
        $fullPath = $this->storagePath.implode("/", array_map("rawurlencode", explode("/", $path)));
        return Url::to($fullPath);
    }

instead remove backslash from rtrim(Config::get('cms.storage.media.path', '/storage/app/media'), '/'); give valid media url.

protected function init()
    {
        $this->storageFolder = self::validatePath(Config::get('cms.storage.media.folder', 'media'), true);
        **$this->storagePath = rtrim(Config::get('cms.storage.media.path', 'storage/app/media'), '/');

@w20k could you look into that? ^

@LukeTowers, will do! I've already been planning to patch few bugs on this week 馃槈

@algofran, could you test without this PR changes (https://github.com/octobercms/october/pull/3536/files)?

@LukeTowers I already tried with fresh october installation
My fix return valid url without using PR #3536 changes
its return invalid url if I use both

@algofran I can't reproduce your fix. Removing the first / does no difference in links for me. And you're only changing the fallback value that's used when cms.storage.media.path is not set in the config, which it is by default, so I find it odd that it should make a difference. What are your app.url and cms.storage.media.path config values? Removing the first / from the actual media path config value results in double folders in the link but without the slash. Adding the subfolder to the beginning doesn't help either.

However by applying PR #4055 it works.

I'm using the following config values:
app..url: example.domain/subfolder
cms.storage.media.path: /storage/app/media

Edit: Also if this is your getPathUrl() looks like this it's incorrect:

public function getPathUrl($path)
{
        $path = $this->validatePath($path);
        return URL::to($this->storagePath.$path);
        $fullPath = $this->storagePath.implode("/", array_map("rawurlencode", explode("/", $path)));
        return Url::to($fullPath);
}

You have two return statements, it should look like this while also applying the fix from PR #4055:

public function getPathUrl($path)
{
        $path = $this->validatePath($path);
        $fullPath = $this->storagePath.implode("/", array_map("rawurlencode", explode("/", $path)));
        return Url::to($fullPath);
}

@adsa95 thanks for noticing my getPathUrl(), I forgot to delete after redoing the fix. I'm not using that on my test.

app.url 'url' => 'http://localhost/app-origin/'
cms.storage.media.path = '/storage/app/media'

I can't reproduce your fix. Removing the first / does no difference in links for me.
If there is no changes use this getPathUrl()

public function getPathUrl($path) 
{
        $path = $this->validatePath($path);
        return $this->storagePath.$path;
}

PR #4055 also works if use this getPathUrl()
``php public function getPathUrl($path) { $path = $this->validatePath($path); $fullPath = $this->storagePath.implode("/", array_map("rawurlencode", explode("/", $path))); return Url::to($fullPath); }

Issues don't get closed until the fix is merged into master FYI

@algofran @adsa95 can you confirm that https://github.com/octobercms/october/pull/4055 solves the issue?

@LukeTowers, it works at my localhost on my root subfolder.
Maybe need to consider if adding more helper (URL) and removing HTTP / HTTPS detection.

@LukeTowers I wasn't able to follow all his steps and reproduce this error exactly, but based on the comments here I would say this is a duplicate of #4039, but the reason #4055 didn't work initially was because he also did other changes to the code, so yes #4055 should solve this issue.

I don't know if this is a Translate issue or related to this but if you have a translatable mediefinder field and switch the locale, the path is introducing an extra \ to the path so the image is not rendering on the backend. This is happening with 447 - no idea if it was there before as this is a new project. On initial load the rendered thumb/path is fine, if you select any locales, even the initial one the path is now wrong.

My S3 config path does not have a slash and all other instances of using the mediafinder are fine, it's translated fields after change is introducing the extra backslash.

https://s3.eu-central-1.amazonaws.com/my-bucket/media//ads/ad_en.png

Was this page helpful?
0 / 5 - 0 ratings