0

Im uploading images to azure blob storage in a project. For logic reason I'm creating a new container for each upload, to group the content. This park works fine. Now I'm trying to setup ImageResizer to enable resizing :) and som other stuff. In all the examples they point to a container as the endpoint, but in my case I have multiple dynamic container, so this is not an option. My question is if someone knows if it should work in my case or if I need to rethink something about the way I store images.

Rasmus Christensen
  • 8,321
  • 12
  • 51
  • 78

1 Answers1

3

According to your requirement, you could try to leverage AzureReader2 to work with Azure blobs, in order to dynamic resize your images from Azure Blob. Since you have miltiple dynamic containers, you could follow the steps below to configure AzureReader2:

Install Package via NuGet

  • ImageResizer.WebConfig

  • ImageResizer.Plugins.AzureReader2

Web.config

<configSections>
    <section name="resizer" type="ImageResizer.ResizerSection" requirePermission="false" />
</configSections>

<resizer>
    <plugins>
      <add name="MvcRoutingShim" />
      <add name="AzureReader2"
           connectionString="{your-storage-connectionstring}"
           prefix="~/cloud/" />
    </plugins>
</resizer>

<system.web>
    <httpModules>
      <add name="ImageResizingModule" type="ImageResizer.InterceptModule" />
    </httpModules>
</system.web>

<system.webServer>
    <modules>
      <add name="ImageResizingModule" type="ImageResizer.InterceptModule" />
    </modules>
</system.webServer>

Result

Here is my test, you could refer to it.

1.Upload images to my Azure Blob

https://brucechen.blob.core.windows.net/images01/test.jpg

https://brucechen.blob.core.windows.net/images01/landscape/test.jpg

https://brucechen.blob.core.windows.net/images02/test.jpg

2.Browser images in my web site as follows:

http://bruce-chen.azurewebsites.net/cloud/images01/test.jpg?width=400

http://bruce-chen.azurewebsites.net/cloud/images01/landscape/test.jpg?width=400

http://bruce-chen.azurewebsites.net/cloud/images02/test.jpg?width=400

Note: your images links should look like:

http(s)://<host-name>:<port>/<prefix-you-configured>/<blob-container-name>/<blob-file-name>?width=200&height=200

Additionally, for pre-resizing your images via ImageResizer, you could follow the answer in this thread. Also, there is anther similar library called Simple.ImageResizer which is free, you could refer to it.

Community
  • 1
  • 1
Bruce Chen
  • 18,207
  • 2
  • 21
  • 35
  • Thanks, must have an error in my web.config as this looks my setup. Do you have the httpmodules included? – Rasmus Christensen Oct 31 '16 at 08:42
  • Thank you very much for clearing it out. It actually was similar to my current config. It turned out the error was the first part of the url. I used the blobs direct url and not the sites url ;) as mentioned in of of the comments here http://stackoverflow.com/questions/14675118/imageresizer-for-azure-using-azurereader2-plugin-not-resizing Why are you using the shim, haven't seen it before? – Rasmus Christensen Oct 31 '16 at 20:06