[英]How can I copy contents of one directory to another with the AWS api?
I want to be able to copy all the contents of folder1 to folder2 and remove it from folder 1. 我希望能够将folder1的所有内容复制到folder2并将其从文件夹1中删除。
I think you can use the S3DirectoryInfo class using AWSSDK(3.xx version) C#. 我认为您可以通过AWSSDK(3.xx版)C#使用S3DirectoryInfo类。 this class has MoveTo method see the code below.
此类具有MoveTo方法,请参见下面的代码。
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)
{
}
}
try this one: 试试这个:
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);
Here once you copied from one to another first folder is getting deleted. 在这里,从一个文件夹复制到另一个文件夹后,第一个文件夹将被删除。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.