当前位置: 首页>>代码示例>>C#>>正文


C# ListObjectsRequest.WithPrefix方法代码示例

本文整理汇总了C#中Amazon.S3.Model.ListObjectsRequest.WithPrefix方法的典型用法代码示例。如果您正苦于以下问题:C# ListObjectsRequest.WithPrefix方法的具体用法?C# ListObjectsRequest.WithPrefix怎么用?C# ListObjectsRequest.WithPrefix使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Amazon.S3.Model.ListObjectsRequest的用法示例。


在下文中一共展示了ListObjectsRequest.WithPrefix方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Index

        public ActionResult Index()
        {
            // get me all objects inside a given folder
            Dictionary<string, double> images = null;

            var request = new ListObjectsRequest();
            request.BucketName = AWSBucket;
            request.WithPrefix(AWSFolder);

            using (AmazonS3 client = Amazon.AWSClientFactory.CreateAmazonS3Client(AWSAccessKey, AWSSecretKey))
            {
                using (ListObjectsResponse response = client.ListObjects(request))
                {
                    images = response.S3Objects.Where(x => x.Key != AWSFolder).ToDictionary(obj => obj.Key, obj => AppHelper.ConvertBytesToMegabytes(obj.Size));
                }
            }

            return View(images);
        }
开发者ID:aherrick,项目名称:AmazonAWS-CRD,代码行数:19,代码来源:HomeController.cs

示例2: ListingObjects

        static void ListingObjects()
        {
            try
            {
                ListObjectsRequest request = new ListObjectsRequest();
                request.BucketName = bucketName;
                using (ListObjectsResponse response = client.ListObjects(request))
                {
                    foreach (S3Object entry in response.S3Objects)
                    {
                        Console.WriteLine("key = {0} size = {1}", entry.Key, entry.Size);
                    }
                }

                // list only things starting with "foo"
                request.WithPrefix("foo");
                using (ListObjectsResponse response = client.ListObjects(request))
                {
                    foreach (S3Object entry in response.S3Objects)
                    {
                        Console.WriteLine("key = {0} size = {1}", entry.Key, entry.Size);
                    }
                }

                // list only things that come after "bar" alphabetically
                request.WithPrefix(null)
                    .WithMarker("bar");
                using (ListObjectsResponse response = client.ListObjects(request))
                {
                    foreach (S3Object entry in response.S3Objects)
                    {
                        Console.WriteLine("key = {0} size = {1}", entry.Key, entry.Size);
                    }
                }

                // only list 3 things
                request.WithPrefix(null)
                    .WithMarker(null)
                    .WithMaxKeys(3);
                using (ListObjectsResponse response = client.ListObjects(request))
                {
                    foreach (S3Object entry in response.S3Objects)
                    {
                        Console.WriteLine("key = {0} size = {1}", entry.Key, entry.Size);
                    }
                }
            }
            catch (AmazonS3Exception amazonS3Exception)
            {
                if (amazonS3Exception.ErrorCode != null && (amazonS3Exception.ErrorCode.Equals("InvalidAccessKeyId") || amazonS3Exception.ErrorCode.Equals("InvalidSecurity")))
                {
                    Console.WriteLine("Please check the provided AWS Credentials.");
                    Console.WriteLine("If you haven't signed up for Amazon S3, please visit http://aws.amazon.com/s3");
                }
                else
                {
                    Console.WriteLine("An error occurred with the message '{0}' when listing objects", amazonS3Exception.Message);
                }
            }
        }
开发者ID:bernardoleary,项目名称:MyBigBro,代码行数:60,代码来源:S3Sample.cs

示例3: GetAppImageArchiveUrls

    public ArrayList GetAppImageArchiveUrls(Hashtable State)
    {
        ArrayList raw_image_list = new ArrayList();
        ArrayList image_list = new ArrayList();
        string AWSAccessKey = ConfigurationManager.AppSettings["AWSAccessKey"];
        string AWSSecretKey = ConfigurationManager.AppSettings["AWSSecretKey"];
        string Bucket = ConfigurationManager.AppSettings["ImageBucket"];
        Amazon.S3.AmazonS3 client = Amazon.AWSClientFactory.CreateAmazonS3Client(AWSAccessKey, AWSSecretKey);
        try
        {
            ListObjectsRequest request = new ListObjectsRequest();
            request.BucketName = Bucket;
            string prefix = "https://s3.amazonaws.com/" + Bucket + "/";
            request.WithPrefix(State["Username"].ToString());
            raw_image_list = GetImages(client, request, prefix, raw_image_list);
            string app_string = "/" + State["SelectedApp"].ToString().Replace(" ","_") + "/";
            foreach (string url in raw_image_list)
            {
                if ( url.Contains(app_string))
                {
                    image_list.Add(url);
                }
            }
        }
        catch (AmazonS3Exception ex)
        {
            Util util = new Util();
            util.LogError(State, ex);
            throw new Exception(ex.Message + ": " + ex.StackTrace);
        }

        return image_list;
    }
开发者ID:dcolonvizi,项目名称:ViziAppsPortal,代码行数:33,代码来源:AmazonS3.cs

示例4: GetStockImageUrls

    public ArrayList GetStockImageUrls(Hashtable State)
    {
        ArrayList image_list = new ArrayList();
        string AWSAccessKey = ConfigurationManager.AppSettings["AWSAccessKey"];
        string AWSSecretKey = ConfigurationManager.AppSettings["AWSSecretKey"];
        string Bucket = ConfigurationManager.AppSettings["ImageBucket"];
        Amazon.S3.AmazonS3 client = Amazon.AWSClientFactory.CreateAmazonS3Client(AWSAccessKey, AWSSecretKey);
        try
        {
            ListObjectsRequest request = new ListObjectsRequest();
            request.BucketName = Bucket;

            // list only things starting with "apps/images"

            string prefix = "https://s3.amazonaws.com/" + Bucket + "/";
            request.WithPrefix("apps/images/bars");
            image_list = GetImages(client, request, prefix, image_list);

            request.WithPrefix("apps/images/blank_buttons");
            image_list = GetImages(client, request, prefix, image_list);

            request.WithPrefix("apps/images/jquery_buttons");
            image_list = GetImages(client, request, prefix, image_list);

            request.WithPrefix("apps/images/bw_dark_icons");
            image_list = GetImages(client,request,prefix, image_list);

            request.WithPrefix("apps/images/bw_light_icons");
            image_list = GetImages(client, request, prefix, image_list);

            request.WithPrefix("apps/images/icon_buttons");
            image_list = GetImages(client, request, prefix, image_list);

            request.WithPrefix("apps/images/navigation_buttons");
            image_list = GetImages(client, request, prefix, image_list);

            request.WithPrefix("apps/images/ratings");
            image_list = GetImages(client, request, prefix, image_list);
        }
        catch (AmazonS3Exception ex)
        {
            Util util = new Util();
            util.LogError(State,ex);
            throw new Exception( ex.Message + ": " + ex.StackTrace);
        }

        return image_list;
    }
开发者ID:dcolonvizi,项目名称:ViziAppsPortal,代码行数:48,代码来源:AmazonS3.cs

示例5: GetS3Objects

 private IEnumerable<S3Object> GetS3Objects(string domain, string path)
 {
     using (AmazonS3 client = GetClient())
     {
         var request = new ListObjectsRequest { BucketName = _bucket };
         request.WithPrefix(MakePath(domain, path.TrimEnd('/') + '/')).WithMaxKeys(1000);
         var objects = new List<S3Object>();
         ListObjectsResponse response;
         do
         {
             response = client.ListObjects(request);
             objects.AddRange(response.S3Objects.Where(entry => CheckKey(domain, entry.Key)));
             if (objects.Count > 0)
             {
                 request.Marker = objects[objects.Count - 1].Key;
             }
         } while (response.IsTruncated);
         return objects;
     }
 }
开发者ID:ridhouan,项目名称:teamlab.v6.5,代码行数:20,代码来源:S3Storage.cs

示例6: GetAccountImageArchiveUrls

    public ArrayList GetAccountImageArchiveUrls(Hashtable State)
    {
        ArrayList raw_image_list = new ArrayList();
        ArrayList image_list = new ArrayList();
        string AWSAccessKey = ConfigurationManager.AppSettings["AWSAccessKey"];
        string AWSSecretKey = ConfigurationManager.AppSettings["AWSSecretKey"];
        string Bucket = ConfigurationManager.AppSettings["ImageBucket"];
        Amazon.S3.AmazonS3 client = Amazon.AWSClientFactory.CreateAmazonS3Client(AWSAccessKey, AWSSecretKey);
        try
        {
            ListObjectsRequest request = new ListObjectsRequest();
            request.BucketName = Bucket;

            // list only things starting with "apps/images"

            string prefix = "https://s3.amazonaws.com/" + Bucket + "/";
            request.WithPrefix(State["Username"].ToString());
            raw_image_list = GetImages(client, request, prefix, raw_image_list);
            foreach (string url in raw_image_list)
            {
                if (url.EndsWith(".jpg") || url.EndsWith(".png") || url.EndsWith(".gif"))
                {
                    image_list.Add(url);
                }
            }
        }
        catch (AmazonS3Exception ex)
        {
            Util util = new Util();
            util.LogError(State, ex);
            throw new Exception(ex.Message + ": " + ex.StackTrace);
        }

        return image_list;
    }
开发者ID:dcolonvizi,项目名称:ViziAppsPortal,代码行数:35,代码来源:AmazonS3.cs

示例7: CopyDirectory

        public override void CopyDirectory(string srcdomain, string srcdir, string newdomain, string newdir)
        {
            string srckey = MakePath(srcdomain, srcdir);
            string dstkey = MakePath(newdomain, newdir);
            //List files from src
            using (AmazonS3 client = GetClient())
            {
                var request = new ListObjectsRequest { BucketName = _bucket };
                request.WithPrefix(srckey);

                using (ListObjectsResponse response = client.ListObjects(request))
                {
                    foreach (S3Object s3Object in response.S3Objects)
                    {
                        if (QuotaController != null)
                        {
                            QuotaController.QuotaUsedAdd(_modulename, newdomain, _dataList.GetData(newdomain), s3Object.Size);
                        }

                        client.CopyObject(new CopyObjectRequest()
                                              .WithSourceBucket(_bucket)
                                              .WithSourceKey(s3Object.Key)
                                              .WithDestinationBucket(_bucket)
                                              .WithDestinationKey(s3Object.Key.Replace(srckey, dstkey)).WithCannedACL(
                                                  GetDomainACL(newdomain)));
                    }
                }
            }
        }
开发者ID:ridhouan,项目名称:teamlab.v6.5,代码行数:29,代码来源:S3Storage.cs

示例8: GetFileSize

 public override long GetFileSize(string domain, string path)
 {
     using (AmazonS3 client = GetClient())
     {
         var request = new ListObjectsRequest { BucketName = _bucket };
         request.WithPrefix(MakePath(domain, path));
         using (ListObjectsResponse response = client.ListObjects(request))
         {
             if (response.S3Objects.Count > 0)
             {
                 return response.S3Objects[0].Size;
             }
             throw new FileNotFoundException("file not found", path);
         }
     }
 }
开发者ID:ridhouan,项目名称:teamlab.v6.5,代码行数:16,代码来源:S3Storage.cs

示例9: IsFile

 public override bool IsFile(string domain, string path)
 {
     using (AmazonS3 client = GetClient())
     {
         var request = new ListObjectsRequest { BucketName = _bucket };
         request.WithPrefix(MakePath(domain, path));
         using (ListObjectsResponse response = client.ListObjects(request))
         {
             return response.S3Objects.Count > 0;
         }
     }
 }
开发者ID:ridhouan,项目名称:teamlab.v6.5,代码行数:12,代码来源:S3Storage.cs

示例10: MoveDirectory

        public override void MoveDirectory(string srcdomain, string srcdir, string newdomain, string newdir)
        {
            string srckey = MakePath(srcdomain, srcdir);
            string dstkey = MakePath(newdomain, newdir);
            //List files from src
            using (AmazonS3 client = GetClient())
            {
                var request = new ListObjectsRequest { BucketName = _bucket };
                request.WithPrefix(srckey);

                using (ListObjectsResponse response = client.ListObjects(request))
                {
                    foreach (S3Object s3Object in response.S3Objects)
                    {
                        client.CopyObject(new CopyObjectRequest()
                                              .WithSourceBucket(_bucket)
                                              .WithSourceKey(s3Object.Key)
                                              .WithDestinationBucket(_bucket)
                                              .WithDestinationKey(s3Object.Key.Replace(srckey, dstkey)).WithCannedACL(
                                                  GetDomainACL(newdomain)));
                        client.DeleteObject(new DeleteObjectRequest().WithBucketName(_bucket).WithKey(s3Object.Key));
                    }
                }
            }
        }
开发者ID:ridhouan,项目名称:teamlab.v6.5,代码行数:25,代码来源:S3Storage.cs

示例11: GetEntries

        public IEnumerable<StorageEntry> GetEntries(string path, string filter)
        {
            var list = new List<StorageEntry>();
            using (var s3 = GetAmazonS3())
            {
                var listRequest = new ListObjectsRequest { BucketName = path };
                listRequest.WithPrefix(filter);
                using (var listResponse = s3.ListObjects(listRequest))
                {
                    foreach (var entry in listResponse.S3Objects)
                    {
                        var cachePath = Path.Combine(_storagePath, entry.Key);

                        var request = new GetObjectRequest().WithBucketName(BucketName).WithKey(entry.Key);
                        using (var response = s3.GetObject(request))
                        {
                            if (!File.Exists(cachePath))
                            {
                                response.WriteResponseStreamToFile(cachePath);
                            }
                        }

                        list.Add(this.ToStorageEntry(cachePath));
                    }
                }
            }

            return list;
        }
开发者ID:takepara,项目名称:MvcPhotos,代码行数:29,代码来源:AwsS3StorageProvider.cs


注:本文中的Amazon.S3.Model.ListObjectsRequest.WithPrefix方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。