C# 如何使用AWS api将一个目录的内容复制到另一个目录? bucketName/folder1/image.jpg bucketName/folder1/someDoc.doc bucketName/folder1/somePdf.pdf bucketName/folder2/someOtherImage.jpeg
我希望能够将folder1的所有内容复制到folder2,并将其从文件夹1中删除。我认为您可以使用AWSSDK(3.x.x版本)C#使用S3DirectoryInfo类。 这个类必须看到下面的代码C# 如何使用AWS api将一个目录的内容复制到另一个目录? bucketName/folder1/image.jpg bucketName/folder1/someDoc.doc bucketName/folder1/somePdf.pdf bucketName/folder2/someOtherImage.jpeg,c#,amazon-s3,C#,Amazon S3,我希望能够将folder1的所有内容复制到folder2,并将其从文件夹1中删除。我认为您可以使用AWSSDK(3.x.x版本)C#使用S3DirectoryInfo类。 这个类必须看到下面的代码 public static void MoveFiles() { BasicAWSCredentials basicCredentials = new BasicAWSCredentials("access key", "secret key")
public static void MoveFiles()
{
BasicAWSCredentials basicCredentials = new BasicAWSCredentials("access key", "secret key");
AmazonS3Config configurationClient = new AmazonS3Config();
configurationClient.RegionEndpoint = RegionEndpoint.EUCentral1;//region of bucket
try
{
using (AmazonS3Client clientConnection = new AmazonS3Client(basicCredentials, configurationClient))
{
S3DirectoryInfo source = new S3DirectoryInfo(clientConnection, "sourcebucketname", "sourcefolderkey");
S3DirectoryInfo target = new S3DirectoryInfo(clientConnection, "destinationbucketname", "destinationfolderkey");
source.MoveTo(target);// move all content from FolderNameUniTest109 to FolderNameUniTest179
}
}
catch(Exception ex)
{
}
}
我认为可以使用AWSSDK(3.x.x版本)C#使用S3DirectoryInfo类。 这个类必须看到下面的代码
public static void MoveFiles()
{
BasicAWSCredentials basicCredentials = new BasicAWSCredentials("access key", "secret key");
AmazonS3Config configurationClient = new AmazonS3Config();
configurationClient.RegionEndpoint = RegionEndpoint.EUCentral1;//region of bucket
try
{
using (AmazonS3Client clientConnection = new AmazonS3Client(basicCredentials, configurationClient))
{
S3DirectoryInfo source = new S3DirectoryInfo(clientConnection, "sourcebucketname", "sourcefolderkey");
S3DirectoryInfo target = new S3DirectoryInfo(clientConnection, "destinationbucketname", "destinationfolderkey");
source.MoveTo(target);// move all content from FolderNameUniTest109 to FolderNameUniTest179
}
}
catch(Exception ex)
{
}
}
试试这个:
PutObjectRequest request = new PutObjectRequest();
request.WithBucketName(BUCKET_NAME);
request.WithKey(PrefixFolder + folderPath[i] + addProjectResponse.ProjectName.Replace("_", " ") + "/");
request.WithTimeout(-1);
request.WithReadWriteTimeout(60 * 60 * 1000);
request.WithContentBody("");
s3Client.PutObject(request);
S3DirectoryInfo source = new S3DirectoryInfo(s3Client, BUCKET_NAME, PrefixFolder + folderPath[i] + addProjectResponse.OldProjectName.Replace("_", " "));
S3DirectoryInfo destination = new S3DirectoryInfo(s3Client, BUCKET_NAME, PrefixFolder + folderPath[i] + addProjectResponse.ProjectName.Replace("_", " "));
source.CopyTo(destination);
source.Delete(true);
此处,一旦您从一个文件夹复制到另一个文件夹,第一个文件夹将被删除。尝试此文件夹:
PutObjectRequest request = new PutObjectRequest();
request.WithBucketName(BUCKET_NAME);
request.WithKey(PrefixFolder + folderPath[i] + addProjectResponse.ProjectName.Replace("_", " ") + "/");
request.WithTimeout(-1);
request.WithReadWriteTimeout(60 * 60 * 1000);
request.WithContentBody("");
s3Client.PutObject(request);
S3DirectoryInfo source = new S3DirectoryInfo(s3Client, BUCKET_NAME, PrefixFolder + folderPath[i] + addProjectResponse.OldProjectName.Replace("_", " "));
S3DirectoryInfo destination = new S3DirectoryInfo(s3Client, BUCKET_NAME, PrefixFolder + folderPath[i] + addProjectResponse.ProjectName.Replace("_", " "));
source.CopyTo(destination);
source.Delete(true);
在这里,一旦您从一个文件夹复制到另一个文件夹,第一个文件夹将被删除