Exemple #1
0
    // List incomplete uploads on the bucket matching specified prefix
    public static void Run(MinioClient minio,
                           string bucketName = "my-bucket-name",
                           string prefix     = "my-object-name",
                           bool recursive    = true)
    {
        try
        {
            Console.WriteLine("Running example for API: ListIncompleteUploads");

            var args = new ListIncompleteUploadsArgs()
                       .WithBucket(bucketName)
                       .WithPrefix(prefix)
                       .WithRecursive(recursive);
            var observable = minio.ListIncompleteUploads(args);

            var subscription = observable.Subscribe(
                item => Console.WriteLine($"OnNext: {item.Key}"),
                ex => Console.WriteLine($"OnError: {ex.Message}"),
                () => Console.WriteLine($"Listed the pending uploads to bucket {bucketName}"));

            Console.WriteLine();
        }
        catch (Exception e)
        {
            Console.WriteLine($"Exception: {e}");
        }
    }
        //ListIncompleteUploads
        public IObservable <Upload> ListIncompleteUploadsAsync(string bucketName, string prefix, bool recursive)
        {
            try
            {
                // Check whether 'mybucket' exist or not.
                var found = minio.BucketExistsAsync(bucketName);
                Task.WaitAll(found);
                if (found.Result)
                {
                    // List all incomplete multipart upload of objects in 'mybucket'
                    IObservable <Upload> observable;
                    return(observable = minio.ListIncompleteUploads(bucketName, prefix, recursive));

                    /*IDisposable subscription = observable.Subscribe(
                     *                  item => Console.WriteLine("OnNext: {0}", item.Key),
                     *                  ex => Console.WriteLine("OnError: {0}", ex.Message),
                     *                  () => Console.WriteLine("OnComplete: {0}"));*/
                }
                else
                {
                    throw new Minio.Exceptions.BucketNotFoundException();
                }
            }
            catch (MinioException e)
            {
                throw;
            }
        }
        static int Main()
        {
            /// Note: s3 AccessKey and SecretKey needs to be added in App.config file
            /// See instructions in README.md on running examples for more information.
            var client = new MinioClient("s3.amazonaws.com", ConfigurationManager.AppSettings["s3AccessKey"],
                                         ConfigurationManager.AppSettings["s3SecretKey"]);

            var items = client.ListIncompleteUploads("my-bucketname", "my-prefixname", true);

            foreach (Upload item in items)
            {
                Console.Out.WriteLine(item.Key);
            }
            return(0);
        }
Exemple #4
0
        private async static Task ListIncompleteUpload_Test1(MinioClient minio)
        {
            Console.Out.WriteLine("Test1: ListIncompleteUploads");
            string bucketName  = GetRandomName(15);
            string objectName  = GetRandomName(10);
            string fileName    = CreateFile(10 * MB);
            string contentType = "gzip";

            await Setup_Test(minio, bucketName);

            CancellationTokenSource cts = new CancellationTokenSource();

            cts.CancelAfter(TimeSpan.FromSeconds(2));
            try
            {
                byte[] bs = File.ReadAllBytes(fileName);
                System.IO.MemoryStream filestream = new System.IO.MemoryStream(bs);
                long file_write_size = filestream.Length;

                await minio.PutObjectAsync(bucketName,
                                           objectName,
                                           filestream,
                                           filestream.Length,
                                           contentType, cts.Token);
            }
            catch (OperationCanceledException)
            {
                IObservable <Upload> observable = minio.ListIncompleteUploads(bucketName);

                IDisposable subscription = observable.Subscribe(
                    item => Assert.AreEqual(item.Key, objectName),
                    ex => Assert.Fail(),
                    () => Console.WriteLine("Listed the pending uploads to bucket " + bucketName));

                await minio.RemoveIncompleteUploadAsync(bucketName, objectName);
            }
            catch (Exception e)
            {
                Console.WriteLine("[Bucket]  Exception: {0}", e);
                Assert.Fail();
            }
            await TearDown(minio, bucketName);

            File.Delete(fileName);
            Console.Out.WriteLine("Test1: ListIncompleteUploads Complete");
        }
Exemple #5
0
        /// <summary>
        /// 列出存储桶中未完整上传的对象。
        /// </summary>
        /// <param name="bucketName">存储桶名称。</param>
        /// <returns></returns>
        public Task <List <ItemUploadInfo> > ListIncompleteUploads(string bucketName)
        {
            if (string.IsNullOrEmpty(bucketName))
            {
                throw new ArgumentNullException(nameof(bucketName));
            }
            ListIncompleteUploadsArgs args = new ListIncompleteUploadsArgs()
                                             .WithBucket(bucketName);
            IObservable <Upload> observable = _client.ListIncompleteUploads(args);

            bool isFinish = false;
            List <ItemUploadInfo> result = new List <ItemUploadInfo>();

            IDisposable subscription = observable.Subscribe(
                item =>
            {
                result.Add(new ItemUploadInfo()
                {
                    Key       = item.Key,
                    Initiated = item.Initiated,
                    UploadId  = item.UploadId,
                });
            },
                ex =>
            {
                isFinish = true;
                throw new Exception(ex.Message, ex);
            },
                () =>
            {
                isFinish = true;
            });

            while (!isFinish)
            {
                Thread.Sleep(0);
            }
            return(Task.FromResult(result));
        }
        // List incomplete uploads on the bucket matching specified prefix
        public static void Run(MinioClient minio,
                               string bucketName = "my-bucket-name",
                               string prefix     = "my-object-name",
                               bool recursive    = true)
        {
            try
            {
                Console.WriteLine("Running example for API: ListIncompleteUploads");

                IObservable <Upload> observable = minio.ListIncompleteUploads(bucketName, prefix, recursive);

                IDisposable subscription = observable.Subscribe(
                    item => Console.WriteLine($"OnNext: {item.Key}"),
                    ex => Console.WriteLine($"OnError: {ex.Message}"),
                    () => Console.WriteLine($"Listed the pending uploads to bucket {bucketName}"));

                Console.WriteLine();
            }
            catch (Exception e)
            {
                Console.WriteLine($"Exception: {e}");
            }
        }