Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Paul 184 posts 646 karma points
    Jan 17, 2022 @ 11:00
    Paul
    0

    Umbraco.StorageProviders.AzureBlob v9 wrong path for CDN images

    Hi All,

    **summary version: When using CDN, the URL returned appears to be incorrect.

    I'm using the HQ package Umbraco.StorageProviders.AzureBlob (https://github.com/umbraco/Umbraco.StorageProviders) to serve media from Azure for my site, but when using the CDN I'm having issues.

    When I view images in the back office all is fine. When I upload images I can see they get added to the Azure storage account and I can see in the cache folder they're created there too.

    When I try and get an image back without using the CDN it works fine; e.g. it'll return: "https://localhost:44330/media/hacjqvy5/design.jpg" So that image is on Azure in my storage account but it's not using the CDN to pull it back. Fine.

    Now when I try to return and image using the CDN (E.g. calling the URL of an image on a page) the following URL is returned - this doesn't work. "https://myAzureCdnUrl.net//hacjqvy5/design.jpg"

    When looking in my storage account I can see the following:

    Container: Umbraco

    Within the Umbraco container > Media and Cache

    Within Media > folder called hacjqvy5 which contains design.jpg

    Within Cache various files with unique 8 digit file names (no extensions) of content type octet-stream

    Does anyone know what I'm doing wrong? (I used to use V7 Blob & azure CDN lots, without issue BTW) Within Startup I have the connectionstring set, the container name set as "Umbraco" as per the above structure and my Azure CDN endpoint URL in the CDN URL field.

    Thanks!

  • Paul 184 posts 646 karma points
    Jan 18, 2022 @ 08:28
    Paul
    0

    Anyone managing to successfully use Umbraco.StorageProviders on Umb v9 with an Azure CDN?

  • Per Bolmstedt 84 posts 380 karma points
    Jan 18, 2022 @ 11:59
    Per Bolmstedt
    0

    We use Azure Storage and Azure CDN for both Umbraco 8 and 9 using the official/recommended packages.

    So we technically never emit (or generate) absolute media URLs, we always generate CDN URLs. We use GetCropUrl() to emit img srcs for example. So I can't say 100% that generating "URLs to media" work, only that generating "CDN URLs to media" works.

    Everything works out of the box after configuring the Storage and CDN settings:

    "Storage": {
      "AzureBlob": {
        "Media": {
          "ConnectionString": "...",
          "ContainerName": "themediacontainer",
          "Cdn": {
            "Url": "https://our-cdn-endpoint.azureedge.net/"
          }
        }
      }
    },
    

    In Startup.ConfigureServices():

            if (!_env.IsDevelopment())
            {
                // Add the Azure Blob Storage file system, ImageSharp image provider/cache and middleware for Media:
                u.AddAzureBlobMediaFileSystem()
                // Optionally add the CDN media URL provider:
                .AddCdnMediaUrlProvider(options =>
                {
                    var settings = _config.GetSection("Umbraco:Storage:AzureBlob:Media:Cdn");
                    options.Url = new Uri(settings.GetValue<string>("Url"));
                });
            }
    

    The CDN endpoint is set to fetch origin media from https://site/media/, so you could say the actual media URL pattern is hard-coded into the CDN configuration.

    Why configuring the CDN media URL provider is necessary I can't recall, but the emitted CDN media URL was broken somehow. It was either lacking an URL segment or containing a superfluous URL segment.

  • Paul 184 posts 646 karma points
    Jan 18, 2022 @ 16:00
    Paul
    0

    Hmm ok thanks. I'll take another look. Currently my startup looks like so:

    // Add the Azure Blob Storage file system, ImageSharp image provider/cache and middleware for Media:
                .AddAzureBlobMediaFileSystem(options => {
                    options.ConnectionString = Environment.GetEnvironmentVariable("UMBRACO__STORAGE__AZUREBLOB__MEDIA__CONNECTIONSTRING");
                    options.ContainerName = Environment.GetEnvironmentVariable("UMBRACO__STORAGE__AZUREBLOB__MEDIA__CONTAINERNAME");
                })
                // Optionally add the CDN media URL provider:
                .AddCdnMediaUrlProvider(options =>
                {
                    options.Url = new Uri(Environment.GetEnvironmentVariable("UMBRACO__STORAGE__AZUREBLOB__MEDIA__CDN__URL"));
                })
    
  • Per Bolmstedt 84 posts 380 karma points
    Jan 18, 2022 @ 16:03
    Per Bolmstedt
    0

    It looks like you're only missing the media segment in the CDN URL. We don't use that segment. So if you just add /media to your CDN URL it looks like it should work.

  • Paul 184 posts 646 karma points
    Jan 20, 2022 @ 08:43
    Paul
    0

    Unfortunately that doesn't work either.

    In the older storage providers the cache folder used to house copies of the media when it was requested; but I'm not seeing that within my cache folder on blob storage.

    The structure of my cache folder on blob storage is as follows: Umbraco > Cache > files (e.g. "445ffae" with no extension and a content type of application/octet-stream). That's quite different to what I used successfully many times in terms of older versions of the storage provider when it was pulling images back via the CDN.

  • Asmus Bartram 2 posts 22 karma points
    Mar 30, 2023 @ 13:33
    Asmus Bartram
    0

    Did you ever find a solution to this?

  • Darryl Challenger 1 post 71 karma points
    Sep 11, 2023 @ 04:40
    Darryl Challenger
    0

    I'm curious also. I'm seeing the same behavior after I moved my app service from Windows to Linux

Please Sign in or register to post replies

Write your reply to:

Draft