本文整理汇总了C#中Amazon.S3.AmazonS3Client.CopyObject方法的典型用法代码示例。如果您正苦于以下问题:C# AmazonS3Client.CopyObject方法的具体用法?C# AmazonS3Client.CopyObject怎么用?C# AmazonS3Client.CopyObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Amazon.S3.AmazonS3Client
的用法示例。
在下文中一共展示了AmazonS3Client.CopyObject方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SoftDeleteFolders
public static void SoftDeleteFolders(ControllerConfiguration context, IEnumerable<string> folders)
{
if (context == null)
throw new ArgumentNullException("context", "Context cannot be null.");
if (folders == null)
throw new ArgumentNullException("folders", "Folders cannot be null.");
using (var client = new AmazonS3Client(context.AwsAccessKeyId, context.AwsSecretAccessKey))
{
foreach (var folder in folders)
{
int maxResults = 100;
int lastCount = maxResults;
while (maxResults == lastCount)
{
using (var listResponse = client.ListObjects(new ListObjectsRequest()
{
BucketName = context.BucketName,
Prefix = folder,
}))
{
lastCount = listResponse.S3Objects.Count;
Parallel.ForEach(listResponse.S3Objects, folderObject =>
{
using (var copyResponse = client.CopyObject(new CopyObjectRequest()
{
SourceBucket = context.BucketName,
DestinationBucket = context.BucketName,
SourceKey = folderObject.Key,
DestinationKey = ".recycled/" + folderObject.Key,
})) { }
});
Parallel.ForEach(listResponse.S3Objects, folderObject =>
{
using (var deleteReponse = client.DeleteObject(new DeleteObjectRequest()
{
BucketName = context.BucketName,
Key = folderObject.Key,
})) { }
});
}
}
}
}
}
示例2: ReplaceAdImages
public void ReplaceAdImages(ref Ad ad, FileName[] filenames)
{
string newFileName = "";
int count = 1;
var id = ad.Id;
var imaa = db.AdImages.Where(x => x.adId.Equals(id)).Count();
count = imaa + 1;
for (int i = 1; i < filenames.Length; i++)
{
IAmazonS3 client;
try
{
using (client = new AmazonS3Client(Amazon.RegionEndpoint.USEast1))
{
GetObjectRequest request = new GetObjectRequest
{
BucketName = _bucketName,
Key = _folderName + filenames[i].fileName
};
using (GetObjectResponse response = client.GetObject(request))
{
string filename = filenames[i].fileName;
if (!System.IO.File.Exists(filename))
{
string extension = System.IO.Path.GetExtension(filenames[i].fileName);
newFileName = ad.Id.ToString() + "_" + count + extension;
client = new AmazonS3Client(Amazon.RegionEndpoint.USEast1);
CopyObjectRequest request1 = new CopyObjectRequest()
{
SourceBucket = _bucketName,
SourceKey = _folderName + filename,
DestinationBucket = _bucketName,
CannedACL = S3CannedACL.PublicRead,//PERMISSION TO FILE PUBLIC ACCESIBLE
DestinationKey = _folderName + newFileName
};
CopyObjectResponse response1 = client.CopyObject(request1);
AdImage image = new AdImage();
image.imageExtension = extension;
image.adId = ad.Id;
db.AdImages.Add(image);
db.SaveChanges();
count++;
DeleteObjectRequest deleteObjectRequest =
new DeleteObjectRequest
{
BucketName = _bucketName,
Key = _folderName + filenames[i].fileName
};
AmazonS3Config config = new AmazonS3Config();
config.ServiceURL = "https://s3.amazonaws.com/";
using (client = Amazon.AWSClientFactory.CreateAmazonS3Client(
_awsAccessKey, _awsSecretKey, config))
{
client.DeleteObject(deleteObjectRequest);
}
}
}
}
}
catch (Exception e)
{
}
}
}
示例3: ObjectSamples
//.........这里部分代码省略.........
try
{
// Issue request
DeleteObjectsResponse response = client.DeleteObjects(request);
}
catch (DeleteObjectsException doe)
{
// Catch error and list error details
DeleteObjectsResponse errorResponse = doe.Response;
foreach (DeletedObject deletedObject in errorResponse.DeletedObjects)
{
Console.WriteLine("Deleted item " + deletedObject.Key);
}
foreach (DeleteError deleteError in errorResponse.DeleteErrors)
{
Console.WriteLine("Error deleting item " + deleteError.Key);
Console.WriteLine(" Code - " + deleteError.Code);
Console.WriteLine(" Message - " + deleteError.Message);
}
}
#endregion
}
{
#region CopyObject Sample
// Create a client
AmazonS3Client client = new AmazonS3Client();
// Create a CopyObject request
CopyObjectRequest request = new CopyObjectRequest
{
SourceBucket = "SampleBucket",
SourceKey = "Item1",
DestinationBucket = "AnotherBucket",
DestinationKey = "Copy1",
CannedACL = S3CannedACL.PublicRead
};
// Issue request
client.CopyObject(request);
#endregion
}
{
#region CopyObject Sample
// Create a client
AmazonS3Client client = new AmazonS3Client();
// Create a CopyObject request
CopyObjectRequest request = new CopyObjectRequest
{
SourceBucket = "SampleBucket",
SourceKey = "Item1",
DestinationBucket = "AnotherBucket",
DestinationKey = "Copy1",
CannedACL = S3CannedACL.PublicRead
};
// Issue request
client.CopyObject(request);
示例4: MoveFile
public bool MoveFile(string sourcePath, string sourceBucket, string destinationPath, string destinationBucket)
{
try
{
var request = new CopyObjectRequest
{
DestinationBucket = destinationBucket,
DestinationKey = destinationPath,
SourceKey = sourcePath,
SourceBucket = sourceBucket
};
using (var s3 = new AmazonS3Client(_connectionInfo.AccessKey, _connectionInfo.SecretKey,
new AmazonS3Config {ServiceURL = "http://s3.amazonaws.com"}))
{
var response = s3.CopyObject(request);
if (response.HttpStatusCode == HttpStatusCode.OK)
{
s3.DeleteObject(new DeleteObjectRequest() {BucketName = sourceBucket, Key = sourcePath});
}
}
return true;
}
catch (Exception ex)
{
Log.Error("Error Moving file", ex);
return false;
}
}