-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Serve Media and App_Plugins using WebRootFileProvider (and allow changing the physical media path) #11783
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
Serve Media and App_Plugins using WebRootFileProvider (and allow changing the physical media path) #11783
Conversation
…esharp are handing requests outside of the wwwroot folder.
Having a distinction between the physical path and browsable URL to media makes total sense and the changes related to this look good. To make the new builder.Services.PostConfigure<GlobalSettings>(options =>
{
if (string.IsNullOrEmpty(options.UmbracoMediaUrl))
{
options .UmbracoMediaUrl = options.UmbracoMediaPath;
}
}); The new public interface IFileProviderFactory
{
IFileProvider Create();
}
// On the existing implementation:
public class PhysicalFileSystem : IPhysicalFileSystem, IFileProviderFactory
{
// Keep all existing code...
public IFileProvider Create() => new PhysicalFileProvider(_rootPath);
}
// To get the 'best performing' IFileProvider and keep backwards compatibility with all current IFileSystem implementations:
var fileProvider = mediaFileManager.FileSystem switch
{
IFileProviderFactory fileProviderFactory => fileProviderFactory.Create(),
var fileSystem => new FileSystemFileProvider(fileSystem)
}; |
On another note: we shouldn't clear/remove the existing ImageSharp |
I've done some testing and pushed my changes to the |
Code in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've pushed some changes that ensure backwards compatibility, most notably keeping the UmbracoMediaPath
setting for the request path/URL and introduce a new UmbracoMediaPhysicalRootPath
setting to change where media is stored on disk.
src/Umbraco.Web.Common/ApplicationBuilder/UmbracoApplicationBuilder.cs
Outdated
Show resolved
Hide resolved
Still not working on cloud.. 404 on the image urls. eg. https://test911.euwest01.umbraco.io/media/ddlokfad/appelsin.png?width=500 |
@bergmania The latest changes should fix the issues on Umbraco Cloud/with the Azure Blob Storage provider. It also reduces the amount of registered services and middleware, as we don't need a custom This also allows easy customization of the response headers for static files, because we're now only calling public class StaticFilesComposer : IComposer
{
public void Compose(IUmbracoBuilder builder)
{
builder.Services.Configure<StaticFileOptions>(options => options.OnPrepareResponse = context =>
{
context.Context.Response.Headers.Add("X-Umbraco-Date", DateTime.Now.ToString("o"));
});
}
} Previously, this would only add this header to static files in your |
Because Umbraco media is now available from the <img src="@home.HeroBackgroundImage.GetCropUrl(200, 200)" width="200" height="200" alt="" asp-append-version="true" /> |
...ests.Integration/Umbraco.Infrastructure/Persistence/Repositories/StylesheetRepositoryTest.cs
Show resolved
Hide resolved
Now it works as expected.. Just a single comment |
Changes looks good to me |
yay 😁 |
Great work! |
hi guys - I just upgraded to umbraco 9.3.0 and set "UmbracoMediaPhysicalRootPath" as per the blog post with a UNC path but it didn't work, i just get 404s for all my media. I also can't find any documentation about these settings apart from what is in the blog post if there is anything extra i need to configure? thanks |
@shearer3000, are you able to test while mapping the UNC path to a drive? I have tested using my NAS that that was mapped to |
Hi @bergmania is universal naming convention not supported for this setting? We don’t use mapped drives |
I had expected it to work, but just tested and see the same issue as you 🤦♂️ . Currently the workaround is to map the UNC to a drive. |
I think another workaround would be to call
Where |
Hi @bergmania @shearer3000 I came here from a different issue mentioned earlier. I had tried both using the UNC which places the new media files inside wwwroot/[ipaddress]/[rest of path] and mapping the UNC to a drive. |
Allows changing the physical path Umbraco media is stored and ensures ImageSharp is still handing requests if the media is outside of wwwroot folder.
Test scenarios:
UmbracoMediaPhysicalRootPath
is changedThis PR adds a new
UmbracoMediaPhysicalRootPath
setting that allows you to change the directory where the physical media files are stored. It's only advised to set this if you want to move the physical files outside of thewwwroot
folder. If not set, the physical path will be resolved from theUmbracoMediaPath
(default value:~/media
, relative to the web root). If you therefore want to change both the URL and physical folder from/media
to e.g./images
, you only have to change theUmbracoMediaPath
.Keep in mind that changing the media path requires you to manually move the existing physical files to the new location. If you change the
UmbracoMediaPath
, all existing URLs will also need to be updated, otherwise all stored values (like references in File Upload, Media Picker and RTE editors) will point to non-existing files and not load anymore.