piranha.core icon indicating copy to clipboard operation
piranha.core copied to clipboard

Media url not correct when using FileStorage in a subdirectory.

Open darkson95 opened this issue 2 years ago • 3 comments

Hello, first of all thank you for the project!

I plan to run the web app on an IIS in a subfolder https://example.com/Piranha. When I run the project in Visual Studio, the application runs directly in root https://localhost:7645.

Now I have the problem that the images from the media library are not displayed on both systems at the same time. In the settings I found the field "Media CDN". If I set that, it works on the IIS, but not locally anymore. If I remove it, it works locally and not on the IIS. I am using the same database for local development and the staging server.

I found the issue #1658, but it does not deal with the media library. Is there an easy way to set the Media CDN to only use it when the HTTP request is not local? Is there a better solution?

darkson95 avatar Jul 06 '22 11:07 darkson95

@tidyui, would the following solution work?

  1. Add a new flag to ConfigModel called something like UseMediaCdnOnLocalhost
  2. Add migrations
  3. Add a checkbox next to the MediaCDN input on the Configuration page to update UseMediaCdnOnLocalhost value
  4. Update the Get method of the Config service to provide the flag
  5. Update the frontend part to use MediaCDN on localhost when UseMediaCdnOnLocalhost is true

sayganov avatar Jul 08 '22 09:07 sayganov

The media CDN is not intended to be used like this, the idea with the CDN setting is if you want to upload images to one location (filesystem, storage) but want to fetch them when rendering the UI from a different URL. The issue would rather be related to that the application path when running in a subdirectory is not considered when generating local file system URL:s.

tidyui avatar Sep 29 '22 07:09 tidyui

I know it's been a while, but I'm having a hard time seeing why this wouldn't work in you case @darkson95. The PublicUrl property for a local asset is calculated to something like:

~/uploads/<id>/<filename>

Given that ~/ should be evaluated to your application root in ASP.NET, if used correctly in the website rendering the image the url should be correct both when the application is running in the root and in an application folder.

Best regards

tidyui avatar Jun 06 '23 06:06 tidyui