Esempio n. 1
0
        // List objects matching optional prefix in a specified bucket.
        public static void Run(MinioClient minio,
                               string bucketName = "my-bucket-name",
                               string prefix     = null,
                               bool recursive    = true)
        {
            try
            {
                Console.WriteLine("Running example for API: ListObjectsAsync");
                ListObjectsArgs listArgs = new ListObjectsArgs()
                                           .WithBucket(bucketName)
                                           .WithPrefix(prefix)
                                           .WithRecursive(recursive);
                IObservable <Item> observable = minio.ListObjectsAsync(listArgs);

                IDisposable subscription = observable.Subscribe(
                    item => Console.WriteLine($"Object: {item.Key}"),
                    ex => Console.WriteLine($"OnError: {ex}"),
                    () => Console.WriteLine($"Listed all objects in bucket {bucketName}\n"));

                listArgs.WithVersions(true);
                IObservable <VersionItem> observableVer = minio.ListObjectVersionsAsync(listArgs);

                IDisposable subscriptionVer = observableVer.Subscribe(
                    item => Console.WriteLine($"Object: {item.Key} Version: {item.VersionId}"),
                    ex => Console.WriteLine($"OnError: {ex}"),
                    () => Console.WriteLine($"Listed all objects in bucket {bucketName}\n"));
                // subscription.Dispose();
            }
            catch (Exception e)
            {
                Console.WriteLine($"[Bucket]  Exception: {e}");
            }
        }
Esempio n. 2
0
    internal ListObjectVersionResponse(ListObjectsArgs args, Tuple <ListVersionsResult, List <Item> > objectList,
                                       IObserver <Item> obs)
    {
        ItemObservable = obs;
        var marker = string.Empty;

        foreach (var item in objectList.Item2)
        {
            BucketObjectsLastItem = item;
            if (objectList.Item1.EncodingType == "url")
            {
                item.Key = HttpUtility.UrlDecode(item.Key);
            }
            ItemObservable.OnNext(item);
        }

        if (objectList.Item1.NextMarker != null)
        {
            if (objectList.Item1.EncodingType == "url")
            {
                NextMarker    = HttpUtility.UrlDecode(objectList.Item1.NextMarker);
                NextKeyMarker = HttpUtility.UrlDecode(objectList.Item1.NextKeyMarker);
                NextVerMarker = HttpUtility.UrlDecode(objectList.Item1.NextVersionIdMarker);
            }
            else
            {
                NextMarker    = objectList.Item1.NextMarker;
                NextKeyMarker = objectList.Item1.NextKeyMarker;
                NextVerMarker = objectList.Item1.NextVersionIdMarker;
            }
        }
        else if (BucketObjectsLastItem != null)
        {
            if (objectList.Item1.EncodingType == "url")
            {
                NextMarker    = HttpUtility.UrlDecode(BucketObjectsLastItem.Key);
                NextKeyMarker = HttpUtility.UrlDecode(BucketObjectsLastItem.Key);
                NextVerMarker = HttpUtility.UrlDecode(BucketObjectsLastItem.VersionId);
            }
            else
            {
                NextMarker    = BucketObjectsLastItem.Key;
                NextKeyMarker = BucketObjectsLastItem.Key;
                NextVerMarker = BucketObjectsLastItem.VersionId;
            }
        }
    }
Esempio n. 3
0
 // List objects matching optional prefix in a specified bucket.
 public static void Run(MinioClient minio,
                        string bucketName = "my-bucket-name",
                        string prefix     = null,
                        bool recursive    = true,
                        bool versions     = false)
 {
     try
     {
         Console.WriteLine("Running example for API: ListObjectsAsync");
         var listArgs = new ListObjectsArgs()
                        .WithBucket(bucketName)
                        .WithPrefix(prefix)
                        .WithRecursive(recursive);
         var observable   = minio.ListObjectsAsync(listArgs);
         var subscription = observable.Subscribe(
             item => Console.WriteLine($"Object: {item.Key}"),
             ex => Console.WriteLine($"OnError: {ex}"),
             () => Console.WriteLine($"Listed all objects in bucket {bucketName}\n"));
     }
     catch (Exception e)
     {
         Console.WriteLine($"[Bucket]  Exception: {e}");
     }
 }
Esempio n. 4
0
        /// <summary>
        /// Queries S3 about the existance and ownership of the given bucket name.
        /// </summary>
        public BucketAccess QueryBucket(string bucketName)
        {
            try
            {
                // recommended technique from amazon: try and list contents of the bucket with 0 maxkeys
                var args = new ListObjectsArgs { MaxKeys = 0 };
                new ListObjectsRequest(this, bucketName, args).GetResponse().Close();

                return BucketAccess.Accessible;
            }
            catch (S3Exception exception)
            {
                switch (exception.ErrorCode)
                {
                    case S3ErrorCode.NoSuchBucket: return BucketAccess.NoSuchBucket;
                    case S3ErrorCode.AccessDenied: return BucketAccess.NotAccessible;
                    default: throw;
                }
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Queries a bucket for a listing of objects it contains. Only objects with keys
        /// beginning with the given prefix will be returned. The DefaultDelimiter will
        /// be used. If you expect a large number of objects to be returned, consider using
        /// ListAllObjects().
        /// </summary>
        public IList<ListEntry> ListObjects(string bucketName, string prefix)
        {
            var args = new ListObjectsArgs { Prefix = prefix, Delimiter = DefaultDelimiter };
            var request = new ListObjectsRequest(this, bucketName, args);

            using (ListObjectsResponse response = request.GetResponse())
            {
                if (response.IsTruncated)
                    throw new Exception("The server truncated the list of items requested. Consider using the ListObjectsRequest class to query for large numbers of items.");

                return response.Entries.ToList();
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Queries a bucket for a listing of objects it contains. Only objects with keys
        /// beginning with the given prefix will be returned.
        /// </summary>
        public IEnumerable<ListEntry> ListAllObjects(string bucketName, string prefix, string delimiter)
        {
            var args = new ListObjectsArgs
            {
                Prefix = prefix,
                Delimiter = delimiter
            };

            while (true)
            {
                var request = new ListObjectsRequest(this, bucketName, args);

                using (var response = request.GetResponse())
                {
                    ListEntry lastEntry = null;

                    foreach (var entry in response.Entries)
                    {
                        lastEntry = entry;
                        yield return entry;
                    }

                    if (response.IsTruncated)
                    {
                        // if you specified a delimiter, S3 is supposed to give us the marker
                        // name to use in order to get the next set of "stuff".
                        if (response.NextMarker != null)
                            args.Marker = response.NextMarker;
                        // if you didn't specify a delimiter, you won't get any CommonPrefixes,
                        // so we'll use the last ObjectEntry's key as the next delimiter.
                        else if (lastEntry is ObjectEntry)
                            args.Marker = (lastEntry as ObjectEntry).Key;
                        else
                            throw new Exception("S3 Server is misbehaving.");
                    }
                    else
                        break; // we're done!
                }
            }
        }