本文整理匯總了C#中AmazonS3.CopyObject方法的典型用法代碼示例。如果您正苦於以下問題:C# AmazonS3.CopyObject方法的具體用法?C# AmazonS3.CopyObject怎麽用?C# AmazonS3.CopyObject使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類AmazonS3
的用法示例。
在下文中一共展示了AmazonS3.CopyObject方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: CopyFile
public static void CopyFile(AmazonS3 s3Client, string sourcekey, string targetkey)
{
String destinationPath = targetkey;
CopyObjectRequest request = new CopyObjectRequest()
{
SourceBucket = BUCKET_NAME,
SourceKey = sourcekey,
DestinationBucket = BUCKET_NAME,
DestinationKey = targetkey
};
CopyObjectResponse response = s3Client.CopyObject(request);
}
示例2: SetObjectStorageClass
/// <summary>
/// Sets the storage class for the S3 Object's Version to the value
/// specified.
/// </summary>
/// <param name="bucketName">The name of the bucket in which the key is stored</param>
/// <param name="key">The key of the S3 Object whose storage class needs changing</param>
/// <param name="version">The version of the S3 Object whose storage class needs changing</param>
/// <param name="sClass">The new Storage Class for the object</param>
/// <param name="s3Client">The Amazon S3 Client to use for S3 specific operations.</param>
/// <seealso cref="T:Amazon.S3.Model.S3StorageClass"/>
public static void SetObjectStorageClass(string bucketName, string key, string version, S3StorageClass sClass, AmazonS3 s3Client)
{
if (sClass > S3StorageClass.ReducedRedundancy ||
sClass < S3StorageClass.Standard)
{
throw new ArgumentException("Invalid value specified for storage class.");
}
if (null == s3Client)
{
throw new ArgumentNullException("s3Client", "Please specify an S3 Client to make service requests.");
}
// Get the existing ACL of the object
GetACLRequest getACLRequest = new GetACLRequest();
getACLRequest.BucketName = bucketName;
getACLRequest.Key = key;
if(version != null)
getACLRequest.VersionId = version;
GetACLResponse getACLResponse = s3Client.GetACL(getACLRequest);
// Set the storage class on the object
CopyObjectRequest copyRequest = new CopyObjectRequest();
copyRequest.SourceBucket = copyRequest.DestinationBucket = bucketName;
copyRequest.SourceKey = copyRequest.DestinationKey = key;
if (version != null)
copyRequest.SourceVersionId = version;
copyRequest.StorageClass = sClass;
// The copyRequest's Metadata directive is COPY by default
CopyObjectResponse copyResponse = s3Client.CopyObject(copyRequest);
// Set the object's original ACL back onto it because a COPY
// operation resets the ACL on the destination object.
SetACLRequest setACLRequest = new SetACLRequest();
setACLRequest.BucketName = bucketName;
setACLRequest.Key = key;
if (version != null)
setACLRequest.VersionId = copyResponse.VersionId;
setACLRequest.ACL = getACLResponse.AccessControlList;
s3Client.SetACL(setACLRequest);
}
示例3: SetWebsiteRedirectLocation
/// <summary>
/// Sets the redirect location for the S3 Object's when being accessed through the S3 website endpoint.
/// </summary>
/// <param name="bucketName">The name of the bucket in which the key is stored</param>
/// <param name="key">The key of the S3 Object</param>
/// <param name="websiteRedirectLocation">The redirect location</param>
/// <param name="s3Client">The Amazon S3 Client to use for S3 specific operations.</param>
public static void SetWebsiteRedirectLocation(string bucketName, string key, string websiteRedirectLocation, AmazonS3 s3Client)
{
CopyObjectRequest copyRequest;
SetACLRequest setACLRequest;
SetupForObjectModification(bucketName, key, null, s3Client, out copyRequest, out setACLRequest);
copyRequest.WebsiteRedirectLocation = websiteRedirectLocation;
CopyObjectResponse copyResponse = s3Client.CopyObject(copyRequest);
if (!string.IsNullOrEmpty(copyResponse.VersionId))
setACLRequest.VersionId = copyResponse.VersionId;
s3Client.SetACL(setACLRequest);
}
示例4: SetServerSideEncryption
/// <summary>
/// Sets the server side encryption method for the S3 Object's Version to the value
/// specified.
/// </summary>
/// <param name="bucketName">The name of the bucket in which the key is stored</param>
/// <param name="key">The key of the S3 Object</param>
/// <param name="version">The version of the S3 Object</param>
/// <param name="method">The server side encryption method</param>
/// <param name="s3Client">The Amazon S3 Client to use for S3 specific operations.</param>
public static void SetServerSideEncryption(string bucketName, string key, string version, ServerSideEncryptionMethod method, AmazonS3 s3Client)
{
CopyObjectRequest copyRequest;
SetACLRequest setACLRequest;
SetupForObjectModification(bucketName, key, version, s3Client, out copyRequest, out setACLRequest);
copyRequest.ServerSideEncryptionMethod = method;
CopyObjectResponse copyResponse = s3Client.CopyObject(copyRequest);
if (!string.IsNullOrEmpty(copyResponse.VersionId))
setACLRequest.VersionId = copyResponse.VersionId;
s3Client.SetACL(setACLRequest);
}
示例5: SetObjectStorageClass
/// <summary>
/// Sets the storage class for the S3 Object's Version to the value
/// specified.
/// </summary>
/// <param name="bucketName">The name of the bucket in which the key is stored</param>
/// <param name="key">The key of the S3 Object whose storage class needs changing</param>
/// <param name="version">The version of the S3 Object whose storage class needs changing</param>
/// <param name="sClass">The new Storage Class for the object</param>
/// <param name="s3Client">The Amazon S3 Client to use for S3 specific operations.</param>
/// <seealso cref="T:Amazon.S3.Model.S3StorageClass"/>
public static void SetObjectStorageClass(string bucketName, string key, string version, S3StorageClass sClass, AmazonS3 s3Client)
{
CopyObjectRequest copyRequest;
SetACLRequest setACLRequest;
SetupForObjectModification(bucketName, key, version, s3Client, out copyRequest, out setACLRequest);
copyRequest.StorageClass = sClass;
CopyObjectResponse copyResponse = s3Client.CopyObject(copyRequest);
if (!string.IsNullOrEmpty(copyResponse.VersionId))
setACLRequest.VersionId = copyResponse.VersionId;
s3Client.SetACL(setACLRequest);
}
示例6: SetObjectStorageClass
public static void SetObjectStorageClass(string bucketName, string key, S3StorageClass sClass, AmazonS3 s3Client)
{
if ((sClass > S3StorageClass.ReducedRedundancy) || (sClass < S3StorageClass.Standard))
{
throw new ArgumentException("Invalid value specified for storage class.");
}
if (s3Client == null)
{
throw new ArgumentNullException("s3Client", "Please specify an S3 Client to make service requests.");
}
CopyObjectRequest request = new CopyObjectRequest();
request.SourceBucket = request.DestinationBucket = bucketName;
request.SourceKey = request.DestinationKey = key;
request.StorageClass = sClass;
s3Client.CopyObject(request);
}
示例7: SetServerSideEncryption
/// <summary>
/// Sets the server side encryption method for the S3 Object's Version to the value
/// specified.
/// </summary>
/// <param name="bucketName">The name of the bucket in which the key is stored</param>
/// <param name="key">The key of the S3 Object</param>
/// <param name="version">The version of the S3 Object</param>
/// <param name="method">The server side encryption method</param>
/// <param name="s3Client">The Amazon S3 Client to use for S3 specific operations.</param>
/// <seealso cref="T:Amazon.S3.Model.S3StorageClass"/>
public static void SetServerSideEncryption(string bucketName, string key, string version, ServerSideEncryptionMethod method, AmazonS3 s3Client)
{
if (null == s3Client)
{
throw new ArgumentNullException("s3Client", "Please specify an S3 Client to make service requests.");
}
// Get the existing ACL of the object
GetACLRequest getACLRequest = new GetACLRequest();
getACLRequest.BucketName = bucketName;
getACLRequest.Key = key;
if (version != null)
getACLRequest.VersionId = version;
GetACLResponse getACLResponse = s3Client.GetACL(getACLRequest);
ListObjectsResponse listObjectResponse = s3Client.ListObjects(new ListObjectsRequest()
.WithBucketName(bucketName)
.WithPrefix(key)
.WithMaxKeys(1));
if (listObjectResponse.S3Objects.Count != 1)
{
throw new ArgumentNullException("No object exists with this bucket name and key.");
}
// Set the storage class on the object
CopyObjectRequest copyRequest = new CopyObjectRequest();
copyRequest.SourceBucket = copyRequest.DestinationBucket = bucketName;
copyRequest.SourceKey = copyRequest.DestinationKey = key;
copyRequest.StorageClass = listObjectResponse.S3Objects[0].StorageClass == "STANDARD" ? S3StorageClass.Standard : S3StorageClass.ReducedRedundancy;
if (version != null)
copyRequest.SourceVersionId = version;
copyRequest.ServerSideEncryptionMethod = method;
// The copyRequest's Metadata directive is COPY by default
CopyObjectResponse copyResponse = s3Client.CopyObject(copyRequest);
// Set the object's original ACL back onto it because a COPY
// operation resets the ACL on the destination object.
SetACLRequest setACLRequest = new SetACLRequest();
setACLRequest.BucketName = bucketName;
setACLRequest.Key = key;
if (version != null)
setACLRequest.VersionId = copyResponse.VersionId;
setACLRequest.ACL = getACLResponse.AccessControlList;
s3Client.SetACL(setACLRequest);
}