【发布时间】:2021-04-29 15:57:08
【问题描述】:
我们正在尝试将 AWS S3 集成到我们的 Kentico 10 应用程序中。
我点击了这个链接:
我在 App_Code => CMSModules => AWSS3 => AWSS3Module.cs 中创建了以下模块
这是 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);
}
}
我在其中一篇文章中读到,只有新文件会被同步。我尝试在媒体文件夹中添加一些文件,但在存储桶中没有添加任何文件。
日志中没有错误。另外,我可以看到该模块已加载到日志中。
存储桶策略似乎正确,或者我在日志中找不到问题。
我做错了什么?
另外,如果上传了文件,我如何获取该文件的 S3 URL?
【问题讨论】: