本文整理匯總了C#中AmazonS3.ListObjects方法的典型用法代碼示例。如果您正苦於以下問題:C# AmazonS3.ListObjects方法的具體用法?C# AmazonS3.ListObjects怎麽用?C# AmazonS3.ListObjects使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類AmazonS3
的用法示例。
在下文中一共展示了AmazonS3.ListObjects方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: ExportAndImport
private static void ExportAndImport(string folder,CloudBlobContainer container, AmazonS3 s3)
{
var listRequest = new ListObjectsRequest{
BucketName = ConfigurationManager.AppSettings["S3Bucket"],
}.WithPrefix(folder);
Console.WriteLine("Fetching all S3 object in " + folder);
var s3response = s3.ListObjects(listRequest);
//Checking if container exists, and creating it if not
if (container.CreateIfNotExists()) {
Console.WriteLine("Creating the blob container");
}
foreach (var s3Item in s3response.S3Objects)
{
if (s3Item.Key == folder) {
continue;
}
if (s3Item.Key.EndsWith("/"))
{
ExportAndImport(s3Item.Key, container, s3);
continue;
}
Console.WriteLine("---------------------------------------------------");
var blockBlob = container.GetBlockBlobReference(s3Item.Key);
Console.WriteLine("Blob: " + blockBlob.Uri.AbsoluteUri);
var id = blockBlob.StartCopyFromBlob(new Uri("http://" + awsServiceUrl + "/" + s3Bucket + "/" + HttpUtility.UrlEncode(s3Item.Key)), null, null, null);
bool continueLoop = true;
while (continueLoop && id == string.Empty)
{
var copyState = blockBlob.CopyState;
if (copyState != null)
{
var percentComplete = copyState.BytesCopied / copyState.TotalBytes;
Console.WriteLine("Status of blob copy...." + copyState.Status + " " + copyState.TotalBytes + " of " + copyState.BytesCopied + "bytes copied. " + string.Format("{0:0.0%}", percentComplete));
if (copyState.Status != CopyStatus.Pending)
{
continueLoop = false;
}
}
System.Threading.Thread.Sleep(1000);
}
}
}
示例2: FindKeys
private void FindKeys(string BucketName, DeleteObjectsRequest deleteRequest, string SearchString, AmazonS3 Client)
{
ListObjectsRequest request = new ListObjectsRequest
{
BucketName = BucketName
};
using (Client)
{
do
{
ListObjectsResponse response = Client.ListObjects(request);
foreach (S3Object entry in response.S3Objects)
{
if (entry.Key.Contains(SearchString))
{
Project.Log(Level.Info, "Deleting file: {0}", entry.Key);
deleteRequest.AddKey(entry.Key, null);
numKeys++;
}
}
// If response is truncated, set the marker to get the next
// set of keys.
if (response.IsTruncated)
{
request.Marker = response.NextMarker;
}
else
{
request = null;
}
} while (request != null);
}
}
示例3: SetupForObjectModification
/// <summary>
/// Sets up the request needed to make an exact copy of the object leaving the parent method
/// the ability to change just the attribute being requested to change.
/// </summary>
/// <param name="bucketName"></param>
/// <param name="key"></param>
/// <param name="version"></param>
/// <param name="s3Client"></param>
/// <param name="copyRequest"></param>
/// <param name="setACLRequest"></param>
static void SetupForObjectModification(string bucketName, string key, string version, AmazonS3 s3Client,
out CopyObjectRequest copyRequest, out SetACLRequest setACLRequest)
{
// 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 object's original ACL back onto it because a COPY
// operation resets the ACL on the destination object.
setACLRequest = new SetACLRequest();
setACLRequest.BucketName = bucketName;
setACLRequest.Key = key;
setACLRequest.ACL = getACLResponse.AccessControlList;
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.");
}
GetObjectMetadataRequest getMetaRequest = new GetObjectMetadataRequest()
{
BucketName = bucketName,
Key = key
};
GetObjectMetadataResponse getMetaResponse = s3Client.GetObjectMetadata(getMetaRequest);
// Set the storage class on the object
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.WebsiteRedirectLocation = getMetaResponse.WebsiteRedirectLocation;
copyRequest.ServerSideEncryptionMethod = getMetaResponse.ServerSideEncryptionMethod;
}
示例4: GetItems
/// <summary>
/// Get Items
/// </summary>
/// <param name="container">Container</param>
/// <param name="client">Client</param>
/// <param name="path">Path</param>
/// <returns>Storage Items</returns>
private IEnumerable<IStorageItem> GetItems(CloudBlobContainer container, AmazonS3 client, string path)
{
if (null != container)
{
var options = new BlobRequestOptions()
{
UseFlatBlobListing = true,
};
return container.ListBlobs(options).Select(b => new Azure(container, b.Uri.ToString())).Where(c => c.Exists());
}
else if (null != client)
{
var request = new ListObjectsRequest()
{
BucketName = path,
};
using (var response = client.ListObjects(request))
{
return response.S3Objects.Select(s3 => new S3(client, path, s3.Key, s3.ETag));
}
}
else
{
return this.GetFiles(path, path, new List<IStorageItem>());
}
}
示例5: QuotaDelete
private long QuotaDelete(string domain, AmazonS3 client, string key)
{
if (QuotaController != null)
{
using (
ListObjectsResponse responce =
client.ListObjects(new ListObjectsRequest().WithBucketName(_bucket).WithPrefix(key)))
{
if (responce.S3Objects != null && responce.S3Objects.Count > 0)
{
long size = Convert.ToInt64(responce.S3Objects[0].Size);
QuotaController.QuotaUsedDelete(_modulename, domain, _dataList.GetData(domain), size);
return size;
}
}
}
return 0;
}
示例6: deleteFile
private void deleteFile(bool hasFile, string fileType, int id)
{
if (hasFile)
{
DeleteObjectRequest request = new DeleteObjectRequest();
request.WithBucketName("intelrecruiter");
ListObjectsRequest listObjReq = new ListObjectsRequest();
listObjReq.WithBucketName("intelrecruiter")
.WithPrefix(fileType + "/" + id.ToString());
using (client = Amazon.AWSClientFactory.CreateAmazonS3Client("AKIAJ47VSG7WMA62WLCA", "3tqlHujlftpk6j/z5OtDw2eg9N2FJtz1RwL8bEa3"))
{
var results = client.ListObjects(listObjReq).S3Objects;
foreach (var obj in results)
{
request.Key = obj.Key;
client.DeleteObject(request);
}
}
}
}
示例7: DoesObjectExist
private bool DoesObjectExist(AmazonS3 client, string objectName)
{
using (ListObjectsResponse listObjectsResponse =
client.ListObjects(new ListObjectsRequest {BucketName = BucketName}))
return listObjectsResponse.S3Objects.Any(o => (o.Key == objectName));
}
示例8: 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);
}
示例9: ListObjects
private static void ListObjects(AmazonS3 s3Client, string bucket)
{
var request = new ListObjectsRequest();
request.WithBucketName(bucket)
.WithPrefix("key")
.WithMaxKeys(4);
do
{
ListObjectsResponse response = s3Client.ListObjects(request);
if (response.IsTruncated)
{
request.Marker = response.NextMarker;
}
else
{
request = null;
}
} while (request != null);
}
示例10: GetFileListing
private void GetFileListing()
{
s3 = AWSClientFactory.CreateAmazonS3Client();
string nextMarker = "";
do
{
ListObjectsRequest lor = new ListObjectsRequest().WithBucketName(BUCKET).WithPrefix(PREFIX).WithMarker(nextMarker);
var response = s3.ListObjects(lor);
if (response.IsTruncated)
nextMarker = response.NextMarker;
else
nextMarker = "";
allFiles.AddRange(response.S3Objects);
Trace.WriteLine(string.Format("Added {0} files. Total files: {1}", response.S3Objects.Count, allFiles.Count));
} while (nextMarker != "");
var buckets = ComputeNode.Catalogs.Values.Cast<ICatalog>().Where(c => c.CatalogName == "WikipediaData").First().Buckets;
var bucketMods = buckets.Select(b => b.Value.BucketMod).ToList();
myFiles = allFiles.Where(f => bucketMods.Contains(f.GetHashCode() % ComputeNode.GlobalBucketCount)).OrderBy(f=>f.Key).ToList();
}