Exemple #1
0
        /// <inheritdoc/>
        public IAsyncResult BeginUploadPart(UploadPartRequest uploadPartRequest, AsyncCallback callback, object state)
        {
            var cmd = UploadPartCommand.Create(GetServiceClient(), _endpoint,
                                               CreateContext(HttpMethod.Put, uploadPartRequest.BucketName, uploadPartRequest.Key),
                                               uploadPartRequest);

            return(OssUtils.BeginOperationHelper(cmd, callback, state));
        }
Exemple #2
0
        /// <inheritdoc/>
        public UploadPartResult UploadPart(UploadPartRequest uploadPartRequest)
        {
            ThrowIfNullRequest(uploadPartRequest);
            var cmd = UploadPartCommand.Create(GetServiceClient(), _endpoint,
                                               CreateContext(HttpMethod.Put, uploadPartRequest.BucketName, uploadPartRequest.Key),
                                               uploadPartRequest);

            return(cmd.Execute());
        }
Exemple #3
0
        private static List<PartETag> BeginUploadPart(String bucketName, String objectName, String fileToUpload,
            String uploadId, int partSize)
        {
            var fileSize = -1;
            using (var fs = File.Open(fileToUpload, FileMode.Open))
            {
                fileSize = (int)fs.Length;
            }

            var partCount = fileSize / partSize;
            if (fileSize % partSize != 0)
            {
                partCount++;
            }

            var partETags = new List<PartETag>();
            for (var i = 0; i < partCount; i++)
            {
                using (FileStream fs = File.Open(fileToUpload, FileMode.Open))
                {
                    var skipBytes = (long)partSize * i;
                    fs.Seek(skipBytes, 0);
                    var size = (partSize < fileSize - skipBytes) ? partSize : (fileSize - skipBytes);
                    var request = new UploadPartRequest(bucketName, objectName, uploadId);
                    request.InputStream = fs;
                    request.PartSize = size;
                    request.PartNumber = i + 1;
                    var result = OssClient.UploadPart(request);
                    partETags.Add(result.PartETag);
                }
            }
            return partETags;
        }