@@ -187,6 +187,7 @@ private void AbortMultipartUpload(string uploadId)
187
187
}
188
188
private async Task UploadUnseekableStreamAsync ( TransferUtilityUploadRequest request , CancellationToken cancellationToken = default ( CancellationToken ) )
189
189
{
190
+ cancellationToken . ThrowIfCancellationRequested ( ) ;
190
191
191
192
int READ_BUFFER_SIZE = this . _s3Client . Config . BufferSize ;
192
193
@@ -201,7 +202,7 @@ private void AbortMultipartUpload(string uploadId)
201
202
} ;
202
203
203
204
var initiateRequest = ConstructInitiateMultipartUploadRequest ( requestEventHandler ) ;
204
- var initiateResponse = await _s3Client . InitiateMultipartUploadAsync ( initiateRequest ) . ConfigureAwait ( false ) ;
205
+ var initiateResponse = await _s3Client . InitiateMultipartUploadAsync ( initiateRequest , cancellationToken ) . ConfigureAwait ( false ) ;
205
206
206
207
try
207
208
{
@@ -219,14 +220,14 @@ private void AbortMultipartUpload(string uploadId)
219
220
int partNumber = 1 ;
220
221
int readBytesCount , readAheadBytesCount = 0 ;
221
222
222
- readBytesCount = await stream . ReadAsync ( readBuffer , 0 , readBuffer . Length ) . ConfigureAwait ( false ) ;
223
+ readBytesCount = await stream . ReadAsync ( readBuffer , 0 , readBuffer . Length , cancellationToken ) . ConfigureAwait ( false ) ;
223
224
224
225
do
225
226
{
226
- await nextUploadBuffer . WriteAsync ( readBuffer , 0 , readBytesCount ) . ConfigureAwait ( false ) ;
227
+ await nextUploadBuffer . WriteAsync ( readBuffer , 0 , readBytesCount , cancellationToken ) . ConfigureAwait ( false ) ;
227
228
// read the stream ahead and process it in the next iteration.
228
229
// this is used to set isLastPart when there is no data left in the stream.
229
- readAheadBytesCount = await stream . ReadAsync ( readBuffer , 0 , readBuffer . Length ) . ConfigureAwait ( false ) ;
230
+ readAheadBytesCount = await stream . ReadAsync ( readBuffer , 0 , readBuffer . Length , cancellationToken ) . ConfigureAwait ( false ) ;
230
231
if ( ( nextUploadBuffer . Position > minPartSize || readAheadBytesCount == 0 ) )
231
232
{
232
233
if ( nextUploadBuffer . Position == 0 )
@@ -247,7 +248,7 @@ private void AbortMultipartUpload(string uploadId)
247
248
nextUploadBuffer . Position = 0 ;
248
249
UploadPartRequest uploadPartRequest = ConstructUploadPartRequestForNonSeekableStream ( nextUploadBuffer , partNumber , partSize , isLastPart , initiateResponse ) ;
249
250
250
- var partResponse = await _s3Client . UploadPartAsync ( uploadPartRequest ) . ConfigureAwait ( false ) ;
251
+ var partResponse = await _s3Client . UploadPartAsync ( uploadPartRequest , cancellationToken ) . ConfigureAwait ( false ) ;
251
252
Logger . DebugFormat ( "Uploaded part {0}. (Last part = {1}, Part size = {2}, Upload Id: {3})" , partNumber , isLastPart , partSize , initiateResponse . UploadId ) ;
252
253
uploadPartResponses . Add ( partResponse ) ;
253
254
partNumber ++ ;
@@ -269,7 +270,7 @@ private void AbortMultipartUpload(string uploadId)
269
270
270
271
this . _uploadResponses = uploadPartResponses ;
271
272
CompleteMultipartUploadRequest compRequest = ConstructCompleteMultipartUploadRequest ( initiateResponse , true , requestEventHandler ) ;
272
- await _s3Client . CompleteMultipartUploadAsync ( compRequest ) . ConfigureAwait ( false ) ;
273
+ await _s3Client . CompleteMultipartUploadAsync ( compRequest , cancellationToken ) . ConfigureAwait ( false ) ;
273
274
Logger . DebugFormat ( "Completed multi part upload. (Part count: {0}, Upload Id: {1})" , uploadPartResponses . Count , initiateResponse . UploadId ) ;
274
275
}
275
276
}
0 commit comments