Kentico 13 Media Library Image Upload Issue

Dane Bezuidenhout asked on November 20, 2023 15:03

What could be causing my newly Uploaded Media Library Images to not display when trying to display them on my web page via their /getmedia URL or when trying to view them via direct path?

Image uploads to the media libraries have been working for months now and suddenly a few weeks ago it started behaving weirdly and not displaying newly uploaded images. I have a Dev environment and a UAT environment, the uploads work fine on the DEV environment, but when uploading them on the UAT environment, it uploads successfully and you can see the image file in the media library and on our filesystem, but the direct path leads to a 404 not found. Sometimes when renaming the file it will randomly work and you can view the file, but most of the time it does not work. Initially when the problem started it happened on the DEV environment as well, but seems to only persist now on the UAT environment, No code changes to anything affecting the Media Library has been made for the last 2-3 months.

Kentico version: v13.0.101

Recent Answers


Brenden Kehren answered on November 20, 2023 16:53

Are you storing your media library files directly on the server or in blob storage?

If directly on the server, then this is most likely your issue. You should look into storing them in something like Azure Blob storage using a custom provider.

Check the following:

  • Web Farm tasks - check to see if there are any failed tasks in there regarding media library files. If so, there's something odd going on with the web farm task either being locked on a file or failing due to a missing file.
  • Event log - check to see if there are any issues in there that would point to an issue with the Web Farm sync not working.
  • Attempt a restart of your web app. If you have hundreds of web farm tasks that need to be synced, then most likely this won't help but it will help eliminate a potential locked process.
  • If you have a lot of pages of web farm tasks waiting to be synced or that have failed, you may want to look into deleting them as they will never end up processing and cause problems long term if that isn't cleaned up.
2 votesVote for this answer Mark as a Correct answer

Dane Bezuidenhout answered on November 21, 2023 08:18 (last edited on November 21, 2023 08:38)

0 votesVote for this answer Mark as a Correct answer

Dane Bezuidenhout answered on November 21, 2023 08:19 (last edited on November 21, 2023 08:38)

0 votesVote for this answer Mark as a Correct answer

Dane Bezuidenhout answered on November 21, 2023 08:20 (last edited on November 21, 2023 13:01)

Hi Brenden, thank you for the feedback and suggestion.

We've done quite a bit of investigation on this. The files are stored in /home/site/wwwroot/(site)/media/(folder)/... on the file system of the Azure VM in a 3 instance App Service cluster and are available to all instances as per https://learn.microsoft.com/en-us/azure/app-service/operating-system-functionality#file-access-across-multiple-instances.

This seemed to suddenly start happening 3 weeks ago. It affects images that were uploaded before this point and were loading fine. To reproduce:

0) Upload a file (not synced from another environment), check that it exists in the above file location and that the metadata for it is in the Kentico database

1) Clear browser cache

2) When requesting https://(host)/(site)/media/(folder)/MyImage.webp in the browser, we get a 301 and redirect to Location /(site)/media/(folder)/MyImage.webp/ followed by a 302 redirect to /.

3) When requesting https://(host)/(site)/getmedia/deb8394b-1232-461d-a67f-112f53361838/MyImage.web, we get a 301 redirect to location /getmedia/deb8394b-1232-461d-a67f-112f53361838/MyImage.webp/, which gets a 404 response.

There are no web farm tasks shown, all web farm servers appear to be healthy. There are no errors in the Event Log. There were no changes to code that could affect routing recently. We found that renaming the file in the media library sometimes fixed the issue, sometimes not. We found that renaming the file locally and then uploading sometimes fixed the issue, sometimes not. We thought it might have to do with Content tree-based routing settings, but changing these to not use home page redirection and to leave URLs as they are had no effect. We also enabled all debug logging and I couldn't see an obvious issue looking at the various logs. We installed Refresh 8 locally, did not have the issue.

It would seem the problem is related to the initial 301 redirect to an invalid path. Any idea what else could cause this in the CMS?

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on November 21, 2023 13:40

If you're in version 13, there is synchronization that happens, in Kentico, by Kentico, to synchronize media files between the CMS instance and the MVC instance. This has nothing to do with Azure and everything to do with Kentico.

Your test needs to be to upload an image and check both websites file systems for that file. Seems you're not using Azure Blog storage, which I'd 100% suggest you do. Doing so will resolve this issue completely and give you redundancy

0 votesVote for this answer Mark as a Correct answer

Dane Bezuidenhout answered on November 21, 2023 13:56

Thank you, but before we make such a change and migrate all the files, we'd need to understand why this would solve the issue. We checked that the file exists on the admin site file system and the live site file system. Note that the admin site is on the multi-instance App Service cluster, so also has 3 instances, but like the live sites, they would share the same OS file system. Do you have any idea why we're getting a 301 redirect?

Also don't understand why the file exists in both the live site and admin sites' file systems instead of just one or the other.

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on November 21, 2023 14:18

I'm not sure how you have your sites set up but if you have 2 individual sites in IIS pointing to 2 different file system locations then you will have 2 independent file locations in which Kentico will need to use its web farm server task to sync them between the CMS and MVC instances.

Take your physical web farm setup out of the mix here, what I stated above is standard Kentico 13 setup; you will have 2 independent file locations on the server.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.