ListMultipartUploads() public method

This operation lists in-progress multipart uploads.
public ListMultipartUploads ( ListMultipartUploadsRequest request ) : ListMultipartUploadsResponse
request ListMultipartUploadsRequest Container for the necessary parameters to execute the ListMultipartUploads service method.
return ListMultipartUploadsResponse
コード例 #1
-1
        static void Main()
        {
            _accessKeyId = Utilities.AwsAccessKey;
            _secretAccessKey = Utilities.AwsSecretKey;
            AmazonS3 s3Client = new AmazonS3Client(_accessKeyId, _secretAccessKey);
            ListMultipartUploadsRequest allMultipartUploadsRequest = new ListMultipartUploadsRequest().WithBucketName(ExistingBucketName);
            ListMultipartUploadsResponse mpUploadsResponse = s3Client.ListMultipartUploads(allMultipartUploadsRequest);
            var objects = new List<Object>();
            foreach (MultipartUpload multipartUpload in mpUploadsResponse.MultipartUploads)
            {
                bool isObjectdFound = false;
                foreach (Object o in objects)
                {
                    if (o.UploadId == multipartUpload.UploadId)
                    {
                        o.Parts.Add(new Part { PartId = o.Parts.Count, Etag = "" });
                        isObjectdFound = true;
                    }
                }
                if (!isObjectdFound)
                {
                    objects.Add(new Object { Parts = new List<Part> { new Part() { Etag = "", PartId = 1 } }, UploadId = multipartUpload.UploadId });
                }
            }
            var result = JsonConvert.SerializeObject(objects);
            var objs = JsonConvert.DeserializeObject<List<Object>>(result);
            //return;

            // List to store upload part responses.
            var uploadResponses = new List<UploadPartResponse>();
            byte[] bytes;
            long contentLength = 0;
            using (var fileStream = new FileStream(FilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            {
                contentLength = fileStream.Length;
                bytes = new byte[contentLength];
                fileStream.Read(bytes, 0, Convert.ToInt32(contentLength));
            }
            // 1. Initialize.
            InitiateMultipartUploadRequest initiateRequest = new InitiateMultipartUploadRequest().WithBucketName(ExistingBucketName).WithKey(KeyName);
            InitiateMultipartUploadResponse initResponse = s3Client.InitiateMultipartUpload(initiateRequest);
            try
            {
                // 2. Upload Parts.
                long partSize = 5 * (long)Math.Pow(2, 20); // 5 MB
                long filePosition = 0;
                for (int i = 1; filePosition < contentLength; i++)
                {
                    byte[] bytesToStream;
                    if (filePosition + partSize < contentLength)
                    {
                        bytesToStream = new byte[partSize];
                        Array.Copy(bytes, filePosition, bytesToStream, 0, partSize);
                    }
                    else
                    {
                        bytesToStream = new byte[contentLength - filePosition];
                        Array.Copy(bytes, filePosition, bytesToStream, 0, contentLength - filePosition);
                    }

                    Stream stream = new MemoryStream(bytesToStream);
                    // Create request to upload a part.
                    UploadPartRequest uploadRequest = new UploadPartRequest()
                        .WithBucketName(ExistingBucketName)
                        .WithKey(KeyName)
                        .WithUploadId(initResponse.UploadId)
                        .WithPartNumber(i)
                        .WithPartSize(partSize)
                        .WithFilePosition(filePosition)
                        .WithTimeout(1000000000)
                        .WithMD5Digest(Convert.ToBase64String(MD5.Create().ComputeHash(bytesToStream)));
                    uploadRequest.WithInputStream(stream);
                    // Upload part and add response to our list.
                    uploadResponses.Add(s3Client.UploadPart(uploadRequest));
                    filePosition += partSize;
                }
                // Step 3: complete.
                CompleteMultipartUploadRequest completeRequest =
                    new CompleteMultipartUploadRequest()
                    .WithBucketName(ExistingBucketName)
                    .WithKey(KeyName)
                    .WithUploadId(initResponse.UploadId)
                    .WithPartETags(uploadResponses);

                CompleteMultipartUploadResponse completeUploadResponse = s3Client.CompleteMultipartUpload(completeRequest);
                Console.WriteLine(completeUploadResponse.ETag);
            }
            catch (Exception exception)
            {
                Console.WriteLine("Exception occurred: {0}", exception.Message);
                s3Client.AbortMultipartUpload(new AbortMultipartUploadRequest()
                    .WithBucketName(ExistingBucketName)
                    .WithKey(KeyName)
                    .WithUploadId(initResponse.UploadId));
            }
        }