Using S3 Storage Provider on MVC K13 Site Not Working

Arnaud Dasprez asked on August 20, 2021 16:48

I am using .net core MVC for a frontend website. I have a module that is getting registered on the front end and backend application that is registering the Module that loads the S3 storage provider, but it is not working and I am not sure why.

Here is a link to a file that I should be seeing in the application. The key exists correctly in my S3 storage as the below: https://d3rw4xodkp6upl.cloudfront.net/hg/files/kirkseyarchitecture/da/da0580cd-3e54-4baf-a2f7-7a9141870004.jpg

But when trying to access it from the website url, it does not work: https://kirksey-dev.hexagroup.us/hg/files/kirkseyarchitecture/da/da0580cd-3e54-4baf-a2f7-7a9141870004.jpg

Any clue why this is not working? In the frontend MVC website, do I have to set the appsettings.json or web.config settings like I do in the CMS admin site? The documentation is not clear on this.

Here is my Module code: using CMS; using CMS.DataEngine; using CMS.EventLog; using CMS.IO;

[assembly: RegisterModule(typeof(KirkseyModule.KirkseyModule))]

namespace KirkseyModule { public class KirkseyModule : Module { public KirkseyModule() : base("KirkseyModule") { }

    protected override void OnInit()
    {
        base.OnInit();

        EventLogInfo.Provider.Set(new EventLogInfo
        {
            EventType = "I",
            Source = nameof(KirkseyModule).ToString(),
            EventCode = "REGISTRATION",
            EventDescription = "Module has been registered."
        });

        var resourceStringer = new RegisterResourceRegistrar();
        resourceStringer.Execute();

        // Creates a new StorageProvider instance for Amazon S3
        var mediaProvider = StorageProvider.CreateAmazonStorageProvider();

        // Specifies the target bucket
        mediaProvider.CustomRootPath = "kirksey-website-kentico";

        // Makes the bucket publicly accessible
        mediaProvider.PublicExternalFolderObject = true;

        // Maps a directory to the provider
        StorageHelper.MapStoragePath("~/hg/files/", mediaProvider);
        StorageHelper.MapStoragePath("~/hg/medialibraries/", mediaProvider);
    }
}

}

Recent Answers


Brian McKeiver answered on August 22, 2021 19:49

Is the assembly that the code is running in marked as discoverable?

edit <project name>AssemblyInfo.cs

Add the AssemblyDiscoverable assembly attribute:

using CMS;

[assembly:AssemblyDiscoverable]

Is the module class present in both the admin tool project bin folder and the .net core live site folder? It needs to be in both sides (admin tool and mvc live site).

1 votesVote for this answer Mark as a Correct answer

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