@@ -60,22 +60,22 @@ public static async Task<bool> UploadFileAsync(
60
60
string objectName ,
61
61
string filePath )
62
62
{
63
- var request = new PutObjectRequest
63
+ try
64
64
{
65
- BucketName = bucketName ,
66
- Key = objectName ,
67
- FilePath = filePath ,
68
- } ;
65
+ var request = new PutObjectRequest
66
+ {
67
+ BucketName = bucketName ,
68
+ Key = objectName ,
69
+ FilePath = filePath ,
70
+ } ;
69
71
70
- var response = await client . PutObjectAsync ( request ) ;
71
- if ( response . HttpStatusCode == System . Net . HttpStatusCode . OK )
72
- {
72
+ await client . PutObjectAsync ( request ) ;
73
73
Console . WriteLine ( $ "Successfully uploaded { objectName } to { bucketName } .") ;
74
74
return true ;
75
75
}
76
- else
76
+ catch ( AmazonS3Exception ex )
77
77
{
78
- Console . WriteLine ( $ "Could not upload { objectName } to { bucketName } . ") ;
78
+ Console . WriteLine ( $ "Could not upload { objectName } to { bucketName } : ' { ex . Message } ' ") ;
79
79
return false ;
80
80
}
81
81
}
@@ -274,13 +274,18 @@ public static async Task<bool> DeleteBucketContentsAsync(IAmazonS3 client, strin
274
274
/// the delete operation.</returns>
275
275
public static async Task < bool > DeleteBucketAsync ( IAmazonS3 client , string bucketName )
276
276
{
277
- var request = new DeleteBucketRequest
277
+ try
278
278
{
279
- BucketName = bucketName ,
280
- } ;
279
+ var request = new DeleteBucketRequest { BucketName = bucketName , } ;
281
280
282
- var response = await client . DeleteBucketAsync ( request ) ;
283
- return response . HttpStatusCode == System . Net . HttpStatusCode . OK ;
281
+ await client . DeleteBucketAsync ( request ) ;
282
+ return true ;
283
+ }
284
+ catch ( AmazonS3Exception ex )
285
+ {
286
+ Console . WriteLine ( $ "Error deleting bucket: { ex . Message } ") ;
287
+ return false ;
288
+ }
284
289
}
285
290
286
291
// snippet-end:[S3.dotnetv3.S3_Basics-DeleteBucket]
0 commit comments