Files not synced to AWS S3

Ashutosh Pandey asked on April 29, 2021 08:39

We are trying to integrate AWS S3 in our Kentico 10 application.

I followed this link:

https://docs.xperience.io/k10/custom-development/working-with-physical-files-using-the-api/configuring-file-system-providers/configuring-amazon-s3#ConfiguringAmazonS3-Medialibrarynotes

I created following module in App_Code => CMSModules => AWSS3 => AWSS3Module.cs

Here is the code of AWSS3Module.cs

using CMS;
using CMS.DataEngine;
using CMS.EventLog;
using CMS.IO;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;

/*
    Make sure following entries exists in web.config => <appSettings>

    <add key="CMSAmazonBucketName" value="" />
    <add key="CMSAmazonAccessKeyID" value="" />
    <add key="CMSAmazonAccessKey" value="" />

    <add key="CMSAmazonPublicAccess" value="true" />
    <add key="CMSAmazonEndPoint" value="" /> 
*/

[assembly: RegisterModule(typeof(AWSS3Module))]

/// <summary>
/// Summary description for AWSS3Module
/// </summary>
public class AWSS3Module: Module
{
    public AWSS3Module(): base("AWSS3Module")
    {
        //
        // TODO: Add constructor logic here
        //
    }

    // Initializes the module. Called when the application starts.
    protected override void OnInit()
    {
        base.OnInit();

        // Assigns a handler to the Insert.After event for OfficeInfo objects
        EventLogProvider.LogInformation("AWSS3 module", "OnInit", "This code is running");

        // Creates a new StorageProvider instance
        AbstractStorageProvider mediaProvider = new StorageProvider("Amazon", "CMS.AmazonStorage");

        // Specifies the target bucket
        mediaProvider.CustomRootPath = ConfigurationManager.AppSettings["CMSAmazonBucketName"];

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

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

I read in one of the post that only new files will be synced. I tried adding few files in the media folder but nothing added in bucket.

There are no errors in logs. Also, I can see the module is loaded in the logs.

Bucket policy seems to be correct or I couldn't find issues in logs.

What am I doing wrong?

Also, if a file is uploaded, how can I get the S3 URL for that file?

Recent Answers


David te Kloese answered on April 29, 2021 09:55

Hi,

is the following line configured correctly:

StorageHelper.MapStoragePath("~/Sitename/", mediaProvider);

As in is "sitename" actually the folder the media lib uses?

All you do here is basically instruct Kentico that there is an "alternative" way of storing files in folder 'x'... if your media lib is not storing in that exact folder it doesn't do anything.

0 votesVote for this answer Mark as a Correct answer

Ashutosh Pandey answered on April 29, 2021 09:59

Sitename here is just for representation which is replaced with actual site name in the code. This folder contains the media folder.

0 votesVote for this answer Mark as a Correct answer

David te Kloese answered on April 29, 2021 10:03

What hotfix are you running? I don't see anything AWS related, but there are a few hotfixes with Storage related description

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on April 29, 2021 15:07

In version 11 and older you need to use the root directory name of CMSStorage. So if your app setting CMSAmazonBucketName is anything but that, it won't work.

0 votesVote for this answer Mark as a Correct answer

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