Esempio n. 1
0
    public Task <UploadPartResponse> UploadPartAsync(string bucketName, string objectKey, int partNumber, string uploadId, Stream content, Action <UploadPartRequest>?config = null, CancellationToken token = default)
    {
        UploadPartRequest req = new UploadPartRequest(bucketName, objectKey, partNumber, uploadId, content);

        config?.Invoke(req);

        return(_multipartOperations.UploadPartAsync(req, token));
    }
        private static async Task UploadPartAsync(TaskCompletionSource <UploadPartResponse> completionSource, IMultipartOperations operations, string bucketName, string objectKey, byte[] data, int length, int partNumber, string uploadId, SemaphoreSlim semaphore, CancellationToken token)
        {
            try
            {
                using (MemoryStream ms = new MemoryStream(data, 0, length))
                {
                    UploadPartResponse result = await operations.UploadPartAsync(new UploadPartRequest(bucketName, objectKey, partNumber, uploadId, ms), token)
                                                .ConfigureAwait(false);

                    completionSource.SetResult(result);
                }
            }
            catch (Exception ex)
            {
                completionSource.SetException(ex);
            }
            finally
            {
                semaphore.Release();
            }
        }