umbraco / Umbraco.StorageProviders

MIT License
29 stars 21 forks source link

Allow different folder names #7

Closed deMD closed 2 years ago

deMD commented 3 years ago

I just tried the StorageProvider in my solution and must say I am happy with the ease of setting it up, however I did run in a few problems I hope can be resolved.

Currently the StorageProvider does not allow another folder name then media. This causes problems in multi region setups where media needs to be stored in region specific media folders (media-eu, media-us etc.) with urls to match. It would be great to have more control over folder/url naming structures without needing to override all kind of hardcoded systems.

ronaldbarendse commented 3 years ago

The AddAzureBlobMediaFileSystem() extension method does indeed only support configuring the default media file system, so you have to manually add the different file systems:

builder
  .AddAzureBlobFileSystem("MediaEu", "~/media-eu")
  .AddAzureBlobFileSystem("MediaUs", "~/media-us")

And then configure the media file system using builder.SetMediaFileSystem(), implement ImageSharps IImageProvider and IImageCache and setup middleware for serving the files. PR https://github.com/umbraco/Umbraco.StorageProviders/pull/9 adds some more extensibility by making it possible to inherit existing classes and passing your own custom file system name to the protected base constructor.


I'm a bit curious to why you would want to have different folders for different regions: aren't they all served from the same webserver? What's the benefit over configuring a CDN?

deMD commented 3 years ago

I'm a bit curious to why you would want to have different folders for different regions: aren't they all served from the same webserver? What's the benefit over configuring a CDN?

Images are not all served from the same webserver. Because we host in different Azure regions media is also served from those different regions. And because we use a cdn in front of the entire web platform for performance and routing to the correct region, eg. www.example.com/nl gets routed to the West Europe azure region while www.example.com/us gets routed to the North America azure region we needed a way to make sure media is picked up from the correct region as well. So the choice was made to stream media via the site instead of configuring a separate cdn for media because then the current CDN can cache the images. But that meant we needed separate folder names, and the AzureFilesystemProvider for v8 does support that.

ronaldbarendse commented 3 years ago

In that case, the webserver in West Europe should be configured to serve the media on /media-eu (which streams from Azure Blob Storage in the same region) and the one in North America on /media-us, right?

The CDN will never request media on /media-us on the webserver in West Europe, so there shouldn't be a need to have that set up. Assuming you sync both Azure Blob Storage containers, they contain the same media and you thereby only use the media path to route to the correct region like you do with the content pages.

deMD commented 3 years ago

In that case, the webserver in West Europe should be configured to serve the media on /media-eu (which streams from Azure Blob Storage in the same region) and the one in North America on /media-us, right?

The CDN will never request media on /media-us on the webserver in West Europe, so there shouldn't be a need to have that set up. Assuming you sync both Azure Blob Storage containers, they contain the same media and you thereby only use the media path to route to the correct region like you do with the content pages.

That would indeed be the idea, so if there is a (documented or build-in) way to do

builder
  .AddAzureBlobFileSystem("MediaEu", "~/media-eu")
  .AddAzureBlobFileSystem("MediaUs", "~/media-us")

That would be great. Isn't there is easy way to extend the default media file system to support those parameters optionally?

ronaldbarendse commented 3 years ago

@deMD The setup I described is supported by using different configuration for the EU and US webservers:

And then use the default configuration setup (AddAzureBlobMediaFileSystem() and UseAzureBlobMediaFileSystem()) and have a way to synchronize both storage containers.

Other setups are also possible, but would currently require writing your own middleware (or inherit from AzureBlobFileSystemMiddleware and provide a custom file system name). I've started on a PR to make this more generic/configurable, which might be of interest to you: https://github.com/umbraco/Umbraco.StorageProviders/pull/11.

ronaldbarendse commented 2 years ago

I'm closing this, because you can already use different folder names using the method described in my previous comment, PR https://github.com/umbraco/Umbraco.StorageProviders/pull/20 now also allows you to configure different container root path and PR https://github.com/umbraco/Umbraco.StorageProviders/pull/36 will make setting this up even easier.