我正在尝试使用 .NET SDK 将文件上传到 Amazon S3。上传工作正常,除了它对上传的文件应用默认权限,即“私人”。
我希望将上传文件的权限设置为“BucketOwnerFullControl”。
下面是我的代码,我不太确定我需要做什么才能让它正常工作。
static string accessKeyID = "";
static string secretAccessKey = "";
static string existingBucketName = "bucket";
static void Main(string[] args)
{
NameValueCollection appConfig = ConfigurationManager.AppSettings;
accessKeyID = appConfig["accesskey"];
secretAccessKey = appConfig["secretkey"];
string[] files = Directory.GetFiles("C:\\amazontestdirectory");
foreach (string fileName in files)
{
try
{
TransferUtility fileTransferUtility = new TransferUtility(accessKeyID, secretAccessKey);
// Upload a file, file name is used as the object key name.
fileTransferUtility.Upload(fileName, existingBucketName);
}
catch (AmazonS3Exception s3Exception)
{
Console.WriteLine("AWS error: " + s3Exception.Message, s3Exception.InnerException);
//Open a file for writing
string errorOutputFileName = System.IO.Path.GetFullPath("C:\\amazontestdirectory\\logs\\errorLog.txt");
//Get a StreamWriter class that can be used to write to the file
if (File.Exists(errorOutputFileName))
{
StreamWriter objStreamWriter;
objStreamWriter = File.AppendText(errorOutputFileName);
objStreamWriter.WriteLine();
objStreamWriter.WriteLine(DateTime.Now.ToString() + " - AWS error: " + s3Exception.Message, s3Exception.InnerException);
//Close the stream
objStreamWriter.Close();
}
}
}
}