@@ -76,7 +76,7 @@ public static async Task Main(string[] args)
7676
7777 // Step 3: Display URL and fields
7878 _uiMethods . DisplayTitle ( "Step 3: Presigned POST URL details" ) ;
79- CreatePresignedPost . DisplayPresignedPostFields ( response ) ;
79+ DisplayPresignedPostFields ( response ) ;
8080 _uiMethods . PressEnter ( _isInteractive ) ;
8181
8282 // Step 4: Upload file
@@ -117,8 +117,20 @@ private static async Task CreateBucketAsync()
117117 {
118118 _uiMethods . DisplayTitle ( "Step 1: Create an S3 bucket" ) ;
119119
120- // Create a unique bucket name for the scenario
121- _bucketName = $ "presigned-post-demo-{ DateTime . Now : yyyyMMddHHmmss} ". ToLower ( ) ;
120+ // Generate a default bucket name for the scenario
121+ var defaultBucketName = $ "presigned-post-demo-{ DateTime . Now : yyyyMMddHHmmss} ". ToLower ( ) ;
122+
123+ // Prompt user for bucket name or use default in non-interactive mode
124+ _bucketName = _uiMethods . GetUserInput (
125+ $ "Enter S3 bucket name (or press Enter for '{ defaultBucketName } '): ",
126+ defaultBucketName ,
127+ _isInteractive ) ;
128+
129+ // Basic validation to ensure bucket name is not empty
130+ if ( string . IsNullOrWhiteSpace ( _bucketName ) )
131+ {
132+ _bucketName = defaultBucketName ;
133+ }
122134
123135 Console . WriteLine ( $ "Creating bucket: { _bucketName } ") ;
124136
@@ -127,53 +139,6 @@ private static async Task CreateBucketAsync()
127139 Console . WriteLine ( $ "Successfully created bucket: { _bucketName } ") ;
128140 }
129141
130- /// <summary>
131- /// Create a presigned POST URL with conditions.
132- /// </summary>
133- /// <param name="s3Client">The Amazon S3 client.</param>
134- /// <param name="bucketName">The name of the bucket.</param>
135- /// <param name="objectKey">The object key (path) where the uploaded file will be stored.</param>
136- /// <param name="expires">When the presigned URL expires.</param>
137- /// <param name="fields">Dictionary of fields to add to the form.</param>
138- /// <param name="conditions">List of conditions to apply.</param>
139- /// <returns>A CreatePresignedPostResponse object with URL and form fields.</returns>
140- // snippet-start:[S3.dotnetv4.Scenario_CreatePresignedPostAsync]
141- private static async Task < CreatePresignedPostResponse > CreatePresignedPostAsync (
142- IAmazonS3 s3Client ,
143- string bucketName ,
144- string objectKey ,
145- DateTime expires ,
146- Dictionary < string , string > ? fields = null ,
147- List < S3PostCondition > ? conditions = null )
148- {
149- var request = new CreatePresignedPostRequest
150- {
151- BucketName = bucketName ,
152- Key = objectKey ,
153- Expires = expires
154- } ;
155-
156- // Add custom fields if provided
157- if ( fields != null )
158- {
159- foreach ( var field in fields )
160- {
161- request . Fields . Add ( field . Key , field . Value ) ;
162- }
163- }
164-
165- // Add conditions if provided
166- if ( conditions != null )
167- {
168- foreach ( var condition in conditions )
169- {
170- request . Conditions . Add ( condition ) ;
171- }
172- }
173-
174- return await s3Client . CreatePresignedPostAsync ( request ) ;
175- }
176- // snippet-end:[S3.dotnetv4.Scenario_CreatePresignedPostAsync]
177142
178143 /// <summary>
179144 /// Create a presigned POST URL.
@@ -189,7 +154,7 @@ private static async Task<CreatePresignedPostResponse> CreatePresignedPostAsync(
189154 // Get S3 client from S3Wrapper
190155 var s3Client = _s3Wrapper . GetS3Client ( ) ;
191156
192- var response = await CreatePresignedPostAsync (
157+ var response = await _s3Wrapper . CreatePresignedPostAsync (
193158 s3Client , _bucketName ! , _objectKey , expiration ) ;
194159
195160 Console . WriteLine ( "Successfully created presigned POST URL" ) ;
@@ -300,6 +265,17 @@ private static async Task VerifyFileExistsAsync()
300265 }
301266 }
302267
268+ private static void DisplayPresignedPostFields ( CreatePresignedPostResponse response )
269+ {
270+ Console . WriteLine ( $ "Presigned POST URL: { response . Url } ") ;
271+ Console . WriteLine ( "Form fields to include:" ) ;
272+
273+ foreach ( var field in response . Fields )
274+ {
275+ Console . WriteLine ( $ " { field . Key } : { field . Value } ") ;
276+ }
277+ }
278+
303279 /// <summary>
304280 /// Clean up resources created by the scenario.
305281 /// </summary>
@@ -322,5 +298,6 @@ private static async Task CleanupAsync()
322298 }
323299 }
324300
301+
325302}
326303// snippet-end:[S3.dotnetv4.CreatePresignedPostBasics]
0 commit comments