Skip to content

Commit

Permalink
Updated S3 examples to v3.5; updated Presigned URL code
Browse files Browse the repository at this point in the history
  • Loading branch information
Doug-AWS committed Sep 2, 2020
1 parent 6abeecc commit 394683c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,18 @@ class GenPresignedURLTest
{
private const string bucketName = "*** bucket name ***";
private const string objectKey = "*** object key ***";
// Specify how long the presigned URL lasts, in hours
private const double timeoutDuration = 12;
// Specify your bucket region (an example region is shown).
private static readonly RegionEndpoint bucketRegion = RegionEndpoint.USWest2;
private static IAmazonS3 s3Client;

public static void Main()
{
s3Client = new AmazonS3Client(bucketRegion);
string urlString = GeneratePreSignedURL();
string urlString = GeneratePreSignedURL(timeoutDuration);
}
static string GeneratePreSignedURL()
static string GeneratePreSignedURL(double duration)
{
string urlString = "";
try
Expand All @@ -30,7 +32,7 @@ static string GeneratePreSignedURL()
{
BucketName = bucketName,
Key = objectKey,
Expires = DateTime.Now.AddMinutes(5)
Expires = DateTime.UtcNow.AddHours(duration)
};
urlString = s3Client.GetPreSignedURL(request1);
}
Expand Down
13 changes: 5 additions & 8 deletions dotnet/example_code_legacy/S3/S3Examples/S3Examples.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,13 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="AWSSDK.Core, Version=3.3.0.0, Culture=neutral, PublicKeyToken=885c28607f98e604, processorArchitecture=MSIL">
<HintPath>..\packages\AWSSDK.Core.3.3.31.7\lib\net45\AWSSDK.Core.dll</HintPath>
<Private>True</Private>
<HintPath>..\packages\AWSSDK.Core.3.5.1.5\lib\net45\AWSSDK.Core.dll</HintPath>
</Reference>
<Reference Include="AWSSDK.S3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=885c28607f98e604, processorArchitecture=MSIL">
<HintPath>..\packages\AWSSDK.S3.3.3.31.15\lib\net45\AWSSDK.S3.dll</HintPath>
<Private>True</Private>
<HintPath>..\packages\AWSSDK.S3.3.5.0.7\lib\net45\AWSSDK.S3.dll</HintPath>
</Reference>
<Reference Include="AWSSDK.SecurityToken, Version=3.3.0.0, Culture=neutral, PublicKeyToken=885c28607f98e604, processorArchitecture=MSIL">
<HintPath>..\packages\AWSSDK.SecurityToken.3.3.4\lib\net45\AWSSDK.SecurityToken.dll</HintPath>
<Private>True</Private>
<HintPath>..\packages\AWSSDK.SecurityToken.3.5.0\lib\net45\AWSSDK.SecurityToken.dll</HintPath>
</Reference>
<Reference Include="AWSSDK.SimpleNotificationService, Version=3.3.0.0, Culture=neutral, PublicKeyToken=885c28607f98e604, processorArchitecture=MSIL">
<HintPath>..\packages\AWSSDK.SimpleNotificationService.3.3.3.18\lib\net45\AWSSDK.SimpleNotificationService.dll</HintPath>
Expand Down Expand Up @@ -111,8 +108,8 @@
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Analyzer Include="..\packages\AWSSDK.S3.3.3.31.15\analyzers\dotnet\cs\AWSSDK.S3.CodeAnalysis.dll" />
<Analyzer Include="..\packages\AWSSDK.SecurityToken.3.3.4\analyzers\dotnet\cs\AWSSDK.SecurityToken.CodeAnalysis.dll" />
<Analyzer Include="..\packages\AWSSDK.S3.3.5.0.7\analyzers\dotnet\cs\AWSSDK.S3.CodeAnalysis.dll" />
<Analyzer Include="..\packages\AWSSDK.SecurityToken.3.5.0\analyzers\dotnet\cs\AWSSDK.SecurityToken.CodeAnalysis.dll" />
<Analyzer Include="..\packages\AWSSDK.SimpleNotificationService.3.3.3.18\analyzers\dotnet\cs\AWSSDK.SimpleNotificationService.CodeAnalysis.dll" />
<Analyzer Include="..\packages\AWSSDK.SQS.3.3.3.54\analyzers\dotnet\cs\AWSSDK.SQS.CodeAnalysis.dll" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@ class UploadObjectUsingPresignedURLTest
private const string bucketName = "*** provide bucket name ***";
private const string objectKey = "*** provide the name for the uploaded object ***";
private const string filePath = "*** provide the full path name of the file to upload ***";
// Specify how long the presigned URL lasts, in hours
private const double timeoutDuration = 12;
// Specify your bucket region (an example region is shown).
private static readonly RegionEndpoint bucketRegion = RegionEndpoint.USWest2;
private static IAmazonS3 s3Client;

public static void Main()
{
s3Client = new AmazonS3Client(bucketRegion);
var url = GeneratePreSignedURL();
var url = GeneratePreSignedURL(timeoutDuration);
UploadObject(url);
}

Expand All @@ -45,14 +47,14 @@ private static void UploadObject(string url)
HttpWebResponse response = httpRequest.GetResponse() as HttpWebResponse;
}

private static string GeneratePreSignedURL()
private static string GeneratePreSignedURL(double duration)
{
var request = new GetPreSignedUrlRequest
{
BucketName = bucketName,
Key = objectKey,
Verb = HttpVerb.PUT,
Expires = DateTime.Now.AddMinutes(5)
Expires = DateTime.UtcNow.AddHours(duration)
};

string url = s3Client.GetPreSignedURL(request);
Expand Down
6 changes: 3 additions & 3 deletions dotnet/example_code_legacy/S3/S3Examples/packages.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="AWSSDK.Core" version="3.3.21.17" targetFramework="net452" />
<package id="AWSSDK.S3" version="3.3.17.2" targetFramework="net452" />
<package id="AWSSDK.SecurityToken" version="3.3.4" targetFramework="net452" />
<package id="AWSSDK.Core" version="3.5.1.5" targetFramework="net452" />
<package id="AWSSDK.S3" version="3.5.0.7" targetFramework="net452" />
<package id="AWSSDK.SecurityToken" version="3.5.0" targetFramework="net452" />
</packages>

0 comments on commit 394683c

Please sign in to comment.