Skip to content

Commit f9e0073

Browse files
committed
pr comments
1 parent 0d39fc3 commit f9e0073

File tree

12 files changed

+110
-277
lines changed

12 files changed

+110
-277
lines changed

.doc_gen/metadata/s3_metadata.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3722,6 +3722,6 @@ s3_CreatePresignedPost:
37223722
- description: Create a presigned POST URL
37233723
genai: most
37243724
snippet_tags:
3725-
- S3.dotnetv4.CreatePresignedPost
3725+
- S3.dotnetv4.Scenario_CreatePresignedPostAsync
37263726
services:
37273727
s3: {CreatePresignedPost}

dotnetv4/DotNetV4Examples.sln

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DynamoDBActions", "DynamoDB
151151
EndProject
152152
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "S3", "S3", "{F929DB74-DD0E-B0EF-AA66-D8703D547BBD}"
153153
EndProject
154-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "S3Actions", "S3\Actions\S3Actions.csproj", "{C0B05982-E721-6989-AFB6-43D7B540248B}"
155-
EndProject
156154
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "S3Tests", "S3\Tests\S3Tests.csproj", "{11497EB7-B702-B537-3CBE-BA2F4F85F313}"
157155
EndProject
158156
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Scenarios", "Scenarios", "{A65C33EA-4F2E-DE85-7501-4389A2100813}"
@@ -373,10 +371,6 @@ Global
373371
{B0F91FE2-6AC5-4FA8-B321-54623A516D4D}.Debug|Any CPU.Build.0 = Debug|Any CPU
374372
{B0F91FE2-6AC5-4FA8-B321-54623A516D4D}.Release|Any CPU.ActiveCfg = Release|Any CPU
375373
{B0F91FE2-6AC5-4FA8-B321-54623A516D4D}.Release|Any CPU.Build.0 = Release|Any CPU
376-
{C0B05982-E721-6989-AFB6-43D7B540248B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
377-
{C0B05982-E721-6989-AFB6-43D7B540248B}.Debug|Any CPU.Build.0 = Debug|Any CPU
378-
{C0B05982-E721-6989-AFB6-43D7B540248B}.Release|Any CPU.ActiveCfg = Release|Any CPU
379-
{C0B05982-E721-6989-AFB6-43D7B540248B}.Release|Any CPU.Build.0 = Release|Any CPU
380374
{11497EB7-B702-B537-3CBE-BA2F4F85F313}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
381375
{11497EB7-B702-B537-3CBE-BA2F4F85F313}.Debug|Any CPU.Build.0 = Debug|Any CPU
382376
{11497EB7-B702-B537-3CBE-BA2F4F85F313}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -453,7 +447,6 @@ Global
453447
{F578CA07-E74F-4F47-9203-C67777D9BB78} = {A1B2C3D4-E5F6-7890-ABCD-EF1234567890}
454448
{E10920BB-6409-41BB-9A9D-813BC37CC3C0} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
455449
{B0F91FE2-6AC5-4FA8-B321-54623A516D4D} = {A1B2C3D4-E5F6-7890-ABCD-EF1234567890}
456-
{C0B05982-E721-6989-AFB6-43D7B540248B} = {F929DB74-DD0E-B0EF-AA66-D8703D547BBD}
457450
{11497EB7-B702-B537-3CBE-BA2F4F85F313} = {F929DB74-DD0E-B0EF-AA66-D8703D547BBD}
458451
{A65C33EA-4F2E-DE85-7501-4389A2100813} = {F929DB74-DD0E-B0EF-AA66-D8703D547BBD}
459452
{2B6F24A0-4569-E8A2-81B4-3925FA4F0320} = {A65C33EA-4F2E-DE85-7501-4389A2100813}

dotnetv4/S3/Actions/CreatePresignedPost.cs

Lines changed: 0 additions & 163 deletions
This file was deleted.

dotnetv4/S3/Actions/S3Actions.csproj

Lines changed: 0 additions & 17 deletions
This file was deleted.

dotnetv4/S3/Actions/Usings.cs

Lines changed: 0 additions & 16 deletions
This file was deleted.

dotnetv4/S3/Scenarios/S3_CreatePresignedPost/Basics.csproj

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
@@ -14,8 +14,4 @@
1414
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.0" />
1515
</ItemGroup>
1616

17-
<ItemGroup>
18-
<ProjectReference Include="..\..\Actions\S3Actions.csproj" />
19-
</ItemGroup>
20-
2117
</Project>

dotnetv4/S3/Scenarios/S3_CreatePresignedPost/CreatePresignedPostBasics.cs

Lines changed: 28 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)