1
我试图使用.NET SDK将文件上传到Amazon S3。上传工作正常,除了它将default permission应用于上传的文件,这是'私人'。使用非默认权限将文件上传到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();
}
}
}
}
是的,经过更多的研究,我发现我不得不使用TransferUtilityUploadRequest。现在所有人都在工作。 –