Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed PutObject for 4.5 projects #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 32 additions & 6 deletions Emkay.S3/S3Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,19 @@ public string[] EnumerateChildren(string bucket, string prefix)
return result.ToArray();
}

/// <summary>
/// <summary>
/// Store the content from a local file into a bucket.
/// The key is the path under which the file will be stored.
/// </summary>
/// <param name="bucketName">The name of the bucket.</param>
/// <param name="key">The key under which the file will be available afterwards.</param>
/// <param name="file">The path to the local file.</param>
/// <param name="publicRead">Flag which indicates if the file is publicly available or not.</param>
public void PutFile(string bucketName, string key, string file, bool publicRead) {
PutFile(bucketName, key, file, publicRead, 0);
}

/// <summary>
/// Store the content from a local file into a bucket.
/// The key is the path under which the file will be stored.
/// </summary>
Expand All @@ -139,21 +151,35 @@ public string[] EnumerateChildren(string bucket, string prefix)
/// <param name="file">The path to the local file.</param>
/// <param name="publicRead">Flag which indicates if the file is publicly available or not.</param>
/// <param name="timeoutMilliseconds">The timeout in milliseconds within the upload must have happend.</param>
public void PutFile(string bucketName, string key, string file, bool publicRead, int timeoutMilliseconds)
[Obsolete("Use the overload without the timeoutMilliseconds instead")]
public void PutFile(string bucketName, string key, string file, bool publicRead, int timeoutMilliseconds)
{
var request = new PutObjectRequest
{
CannedACL = publicRead ? S3CannedACL.PublicRead : S3CannedACL.Private,
FilePath = file,
BucketName = bucketName,
Key = key,
Timeout = TimeSpan.FromMilliseconds(timeoutMilliseconds)
};

_amazonS3Client.PutObject(request);
}

/// <summary>
/// <summary>
/// Store the content from a local file into a bucket.
/// The key is the path under which the file will be stored.
/// Use this overload to add custom headers
/// </summary>
/// <param name="bucketName">The name of the bucket.</param>
/// <param name="key">The key under which the file will be available afterwards.</param>
/// <param name="file">The path to the local file.</param>
/// <param name="headers">The custom headers to be added to the file</param>
/// <param name="publicRead">Flag which indicates if the file is publicly available or not.</param>
public void PutFileWithHeaders(string bucketName, string key, string file, NameValueCollection headers, bool publicRead) {
PutFileWithHeaders(bucketName, key, file, headers, publicRead, 0);
}

/// <summary>
/// Store the content from a local file into a bucket.
/// The key is the path under which the file will be stored.
/// Use this overload to add custom headers
Expand All @@ -164,15 +190,15 @@ public void PutFile(string bucketName, string key, string file, bool publicRead,
/// <param name="headers">The custom headers to be added to the file</param>
/// <param name="publicRead">Flag which indicates if the file is publicly available or not.</param>
/// <param name="timeoutMilliseconds">The timeout in milliseconds within the upload must have happend.</param>
[Obsolete("Use the overload without the timeoutMilliseconds instead")]
public void PutFileWithHeaders(string bucketName, string key, string file, NameValueCollection headers, bool publicRead, int timeoutMilliseconds)
{
var request = new PutObjectRequest
{
CannedACL = publicRead ? S3CannedACL.PublicRead : S3CannedACL.Private,
FilePath = file,
BucketName = bucketName,
Key = key,
Timeout = TimeSpan.FromMilliseconds(timeoutMilliseconds)
Key = key
};

foreach (var headerKey in headers.AllKeys)
Expand Down