Class S3FileSystem
Amazon S3 file system implementation.
Inherited Members
Namespace: Innovt.Cloud.AWS.S3
Assembly: Innovt.Cloud.AWS.S3.dll
Syntax
public class S3FileSystem : AwsBaseService, IDisposable, IFileSystem
Constructors
| Edit this page View SourceS3FileSystem(ILogger, IAwsConfiguration)
Initializes a new instance of the S3FileSystem class.
Declaration
public S3FileSystem(ILogger logger, IAwsConfiguration configuration)
Parameters
Type | Name | Description |
---|---|---|
ILogger | logger | The logger. |
IAwsConfiguration | configuration | The AWS configuration. |
S3FileSystem(ILogger, IAwsConfiguration, string)
Initializes a new instance of the S3FileSystem class with a specific AWS region.
Declaration
public S3FileSystem(ILogger logger, IAwsConfiguration configuration, string region)
Parameters
Type | Name | Description |
---|---|---|
ILogger | logger | The logger. |
IAwsConfiguration | configuration | The AWS configuration. |
string | region | The AWS region. |
Methods
| Edit this page View SourceCopyObject(string, string, string, string, string, string, CancellationToken)
Asynchronously copies an object (file or folder) from the source bucket to the destination bucket.
Declaration
public Task<bool> CopyObject(string sourceBucket, string sourceKey, string destinationBucket, string destinationKey, string serverSideEncryptionMethod = null, string fileAcl = null, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
string | sourceBucket | The source bucket name. |
string | sourceKey | The source key of the object to copy. |
string | destinationBucket | The destination bucket name. |
string | destinationKey | The destination key for the copied object. |
string | serverSideEncryptionMethod | The server-side encryption method (optional). |
string | fileAcl | The file access control for the copied object (optional). |
CancellationToken | cancellationToken | A token to cancel the asynchronous operation (optional). |
Returns
Type | Description |
---|---|
Task<bool> | True if the object was successfully copied; otherwise, false. |
DeleteObject(string, string)
Synchronously deletes an object (file or folder) from the specified Amazon S3 bucket.
Declaration
public bool DeleteObject(string bucketName, string key)
Parameters
Type | Name | Description |
---|---|---|
string | bucketName | The name of the S3 bucket. |
string | key | The key of the object to delete. |
Returns
Type | Description |
---|---|
bool | True if the object was successfully deleted; otherwise, false. |
DeleteObjectAsync(string, string, CancellationToken)
Asynchronously deletes an object (file or folder) from the specified Amazon S3 bucket.
Declaration
public Task<bool> DeleteObjectAsync(string bucketName, string key, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
string | bucketName | The name of the S3 bucket. |
string | key | The key of the object to delete. |
CancellationToken | cancellationToken | A token to cancel the asynchronous operation (optional). |
Returns
Type | Description |
---|---|
Task<bool> | True if the object was successfully deleted; otherwise, false. |
DisposeServices()
Disposes the S3 client instance.
Declaration
protected override void DisposeServices()
Overrides
| Edit this page View SourceDownload(string, string, string)
Downloads a file from an Amazon S3 bucket.
Declaration
public void Download(string bucketName, string fileName, string destination)
Parameters
Type | Name | Description |
---|---|---|
string | bucketName | The name of the S3 bucket. |
string | fileName | The name of the file to download. |
string | destination | The local file path to save the downloaded file. |
DownloadStream(string)
Downloads a file from an Amazon S3 bucket as a stream using the provided URL.
Declaration
public Stream DownloadStream(string url)
Parameters
Type | Name | Description |
---|---|---|
string | url | The URL of the file to download from Amazon S3. |
Returns
Type | Description |
---|---|
Stream | A stream containing the downloaded file's content. |
DownloadStream(string, string)
Downloads a file from an Amazon S3 bucket as a stream.
Declaration
public Stream DownloadStream(string bucketName, string fileName)
Parameters
Type | Name | Description |
---|---|---|
string | bucketName | The name of the S3 bucket. |
string | fileName | The name of the file to download. |
Returns
Type | Description |
---|---|
Stream | A stream containing the downloaded file's content. |
DownloadStreamAsync(string, string, CancellationToken)
Asynchronously downloads a file from an Amazon S3 bucket as a stream.
Declaration
public Task<Stream> DownloadStreamAsync(string bucketName, string fileName, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
string | bucketName | The name of the S3 bucket. |
string | fileName | The name of the file to download. |
CancellationToken | cancellationToken | A token to cancel the asynchronous operation (optional). |
Returns
Type | Description |
---|---|
Task<Stream> | A stream containing the downloaded file's content. |
DownloadStreamAsync(string, CancellationToken)
Asynchronously downloads a file from an Amazon S3 bucket as a stream using the provided URL.
Declaration
public Task<Stream> DownloadStreamAsync(string url, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
string | url | The URL of the file to download from Amazon S3. |
CancellationToken | cancellationToken | A token to cancel the asynchronous operation (optional). |
Returns
Type | Description |
---|---|
Task<Stream> | A stream containing the downloaded file's content. |
ExtractBucketFromGetUrl(string)
Extracts bucket name and file key from the S3 bucket URL.
Declaration
public (string bucket, string fileKey) ExtractBucketFromGetUrl(string bucketUrl)
Parameters
Type | Name | Description |
---|---|---|
string | bucketUrl | The S3 bucket URL. |
Returns
Type | Description |
---|---|
(string bucket, string fileKey) | A tuple containing the bucket name and the file key. |
FileExistsAsync(string, string, CancellationToken)
Asynchronously checks if a file exists in the specified Amazon S3 bucket.
Declaration
public Task<bool> FileExistsAsync(string bucketName, string key, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
string | bucketName | The name of the S3 bucket. |
string | key | The key representing the file in the S3 bucket. |
CancellationToken | cancellationToken | A token to cancel the asynchronous operation (optional). |
Returns
Type | Description |
---|---|
Task<bool> | True if the file exists; otherwise, false. |
FolderExists(string, string)
Synchronously checks if a folder exists in the specified Amazon S3 bucket.
Declaration
public bool FolderExists(string bucketName, string key)
Parameters
Type | Name | Description |
---|---|---|
string | bucketName | The name of the S3 bucket. |
string | key | The key representing the folder in the S3 bucket. |
Returns
Type | Description |
---|---|
bool | True if the folder exists; otherwise, false. |
FolderExistsAsync(string, string, CancellationToken)
Asynchronously checks if a folder exists in the specified Amazon S3 bucket.
Declaration
public Task<bool> FolderExistsAsync(string bucketName, string key, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
string | bucketName | The name of the S3 bucket. |
string | key | The key representing the folder in the S3 bucket. |
CancellationToken | cancellationToken | A token to cancel the asynchronous operation (optional). |
Returns
Type | Description |
---|---|
Task<bool> | True if the folder exists; otherwise, false. |
GeneratePreSignedUrl(string, string, DateTime, IDictionary<string, object>)
Generates a pre-signed URL for accessing an object in the S3 bucket.
Declaration
public string GeneratePreSignedUrl(string bucketName, string key, DateTime expiration, IDictionary<string, object> additionalProperties)
Parameters
Type | Name | Description |
---|---|---|
string | bucketName | The name of the S3 bucket. |
string | key | The key of the object in the S3 bucket. |
DateTime | expiration | The expiration date and time for the pre-signed URL. |
IDictionary<string, object> | additionalProperties | Additional properties for the pre-signed URL (optional). |
Returns
Type | Description |
---|---|
string | The pre-signed URL for accessing the object. |
GetObjectContentAsync(string, string, Encoding, CancellationToken)
Gets the content of the object from the specified URL asynchronously.
Declaration
public Task<string> GetObjectContentAsync(string bucketName, string key, Encoding encoding, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
string | bucketName | The Bucket name. |
string | key | The file url |
Encoding | encoding | |
CancellationToken | cancellationToken |
Returns
Type | Description |
---|---|
Task<string> |
GetObjectContentAsync(string, Encoding, CancellationToken)
Asynchronously gets the content of an object from a specified URL with the given encoding.
Declaration
public Task<string> GetObjectContentAsync(string url, Encoding encoding, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
string | url | The URL of the object to retrieve. |
Encoding | encoding | The encoding to use for reading the object's content. |
CancellationToken | cancellationToken | A token to cancel the asynchronous operation (optional). |
Returns
Type | Description |
---|---|
Task<string> | The content of the object as a string. |
GetObjectFromJsonAsync<T>(Uri, CancellationToken)
When you need to get a content from Json file as an typed method.
Declaration
public Task<T> GetObjectFromJsonAsync<T>(Uri filePath, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
Uri | filePath | |
CancellationToken | cancellationToken |
Returns
Type | Description |
---|---|
Task<T> |
Type Parameters
Name | Description |
---|---|
T |
GetPreSignedUrl(string, string, DateTime)
Gets a pre-signed URL for accessing an object in the S3 bucket.
Declaration
public string GetPreSignedUrl(string bucketName, string key, DateTime expires)
Parameters
Type | Name | Description |
---|---|---|
string | bucketName | The name of the S3 bucket. |
string | key | The key of the object in the S3 bucket. |
DateTime | expires | The expiration date and time for the pre-signed URL. |
Returns
Type | Description |
---|---|
string | The pre-signed URL for accessing the object. |
PutObject(string, Stream, string, string, string, string)
Uploads a stream to an Amazon S3 bucket.
Declaration
public string PutObject(string bucketName, Stream stream, string fileName, string contentType = null, string serverSideEncryptionMethod = null, string fileAcl = null)
Parameters
Type | Name | Description |
---|---|---|
string | bucketName | The name of the S3 bucket. |
Stream | stream | The stream to upload. |
string | fileName | The name to assign to the uploaded file. |
string | contentType | The content type of the file (optional). |
string | serverSideEncryptionMethod | The server-side encryption method (optional). |
string | fileAcl | The file access control list (optional). |
Returns
Type | Description |
---|---|
string | The key of the uploaded object in the S3 bucket. |
PutObject(string, string, string, string, string)
Uploads a file to an Amazon S3 bucket.
Declaration
public string PutObject(string bucketName, string filePath, string contentType = null, string serverSideEncryptionMethod = null, string fileAcl = null)
Parameters
Type | Name | Description |
---|---|---|
string | bucketName | The name of the S3 bucket. |
string | filePath | The local file path of the file to upload. |
string | contentType | The content type of the file (optional). |
string | serverSideEncryptionMethod | The server-side encryption method (optional). |
string | fileAcl | The file access control list (optional). |
Returns
Type | Description |
---|---|
string | The key of the uploaded object in the S3 bucket. |
PutObjectAsync(string, Stream, string, string, string, string, CancellationToken)
Asynchronously uploads a stream to an Amazon S3 bucket.
Declaration
public Task<string> PutObjectAsync(string bucketName, Stream stream, string fileName, string contentType = null, string serverSideEncryptionMethod = null, string fileAcl = null, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
string | bucketName | The name of the S3 bucket. |
Stream | stream | The stream to upload. |
string | fileName | The name to assign to the uploaded file. |
string | contentType | The content type of the file (optional). |
string | serverSideEncryptionMethod | The server-side encryption method (optional). |
string | fileAcl | The file access control list (optional). |
CancellationToken | cancellationToken | A token to cancel the asynchronous operation (optional). |
Returns
Type | Description |
---|---|
Task<string> | The key of the uploaded object in the S3 bucket. |
PutObjectAsync(string, string, string, string, string, CancellationToken)
Asynchronously uploads a file to an Amazon S3 bucket.
Declaration
public Task<string> PutObjectAsync(string bucketName, string filePath, string contentType = null, string serverSideEncryptionMethod = null, string fileAcl = null, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
string | bucketName | The name of the S3 bucket. |
string | filePath | The local file path of the file to upload. |
string | contentType | The content type of the file (optional). |
string | serverSideEncryptionMethod | The server-side encryption method (optional). |
string | fileAcl | The file access control list (optional). |
CancellationToken | cancellationToken | A token to cancel the asynchronous operation (optional). |
Returns
Type | Description |
---|---|
Task<string> | The key of the uploaded object in the S3 bucket. |
Upload(string, Stream, string, IList<KeyValuePair<string, string>>, string, string)
Uploads a file to the specified Amazon S3 bucket from a stream.
Declaration
public string Upload(string bucketName, Stream stream, string fileName, IList<KeyValuePair<string, string>> metadata = null, string serverSideEncryptionMethod = null, string fileAcl = null)
Parameters
Type | Name | Description |
---|---|---|
string | bucketName | The name of the S3 bucket. |
Stream | stream | The stream containing the file content to upload. |
string | fileName | The name of the file to upload. |
IList<KeyValuePair<string, string>> | metadata | Metadata key-value pairs for the uploaded file (optional). |
string | serverSideEncryptionMethod | The server-side encryption method (optional). |
string | fileAcl | The file access control for the uploaded file (optional). |
Returns
Type | Description |
---|---|
string | The URL of the uploaded file. |
Upload(string, string, IList<KeyValuePair<string, string>>, string, string)
Uploads a file to the specified Amazon S3 bucket from a local file path.
Declaration
public string Upload(string bucketName, string filePath, IList<KeyValuePair<string, string>> metadata = null, string serverSideEncryptionMethod = null, string fileAcl = null)
Parameters
Type | Name | Description |
---|---|---|
string | bucketName | The name of the S3 bucket. |
string | filePath | The local file path to upload. |
IList<KeyValuePair<string, string>> | metadata | Metadata key-value pairs for the uploaded file (optional). |
string | serverSideEncryptionMethod | The server-side encryption method (optional). |
string | fileAcl | The file access control for the uploaded file (optional). |
Returns
Type | Description |
---|---|
string | The URL of the uploaded file. |
UploadAsJsonAsync<T>(string, T, string, IList<KeyValuePair<string, string>>, string, string, CancellationToken)
Asynchronously uploads an object serialized as JSON to the specified Amazon S3 bucket.
Declaration
public Task<string> UploadAsJsonAsync<T>(string bucketName, T obj, string fileName, IList<KeyValuePair<string, string>> metadata = null, string serverSideEncryptionMethod = null, string fileAcl = null, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
string | bucketName | The name of the S3 bucket. |
T | obj | The object to serialize and upload. |
string | fileName | The name of the file to use for the uploaded object. |
IList<KeyValuePair<string, string>> | metadata | Metadata key-value pairs for the uploaded object (optional). |
string | serverSideEncryptionMethod | The server-side encryption method (optional). |
string | fileAcl | The file access control for the uploaded object (optional). |
CancellationToken | cancellationToken | A token to cancel the asynchronous operation (optional). |
Returns
Type | Description |
---|---|
Task<string> | The URL of the uploaded object. |
Type Parameters
Name | Description |
---|---|
T | The type of the object to serialize. |
UploadAsync(string, Stream, string, IList<KeyValuePair<string, string>>, string, string, CancellationToken)
Asynchronously uploads a file to the specified Amazon S3 bucket from a stream.
Declaration
public Task<string> UploadAsync(string bucketName, Stream stream, string fileName, IList<KeyValuePair<string, string>> metadata = null, string serverSideEncryptionMethod = null, string fileAcl = null, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
string | bucketName | The name of the S3 bucket. |
Stream | stream | The stream containing the file content to upload. |
string | fileName | The name of the file to upload. |
IList<KeyValuePair<string, string>> | metadata | Metadata key-value pairs for the uploaded file (optional). |
string | serverSideEncryptionMethod | The server-side encryption method (optional). |
string | fileAcl | The file access control for the uploaded file (optional). |
CancellationToken | cancellationToken | A token to cancel the asynchronous operation (optional). |
Returns
Type | Description |
---|---|
Task<string> | The URL of the uploaded file. |
UploadAsync(string, string, IList<KeyValuePair<string, string>>, string, string, CancellationToken)
Asynchronously uploads an object from a local file path to the specified Amazon S3 bucket.
Declaration
public Task<string> UploadAsync(string bucketName, string filePath, IList<KeyValuePair<string, string>> metadata = null, string serverSideEncryptionMethod = null, string fileAcl = null, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
string | bucketName | The name of the S3 bucket. |
string | filePath | The local file path to upload. |
IList<KeyValuePair<string, string>> | metadata | Metadata key-value pairs for the uploaded object (optional). |
string | serverSideEncryptionMethod | The server-side encryption method (optional). |
string | fileAcl | The file access control for the uploaded object (optional). |
CancellationToken | cancellationToken | A token to cancel the asynchronous operation (optional). |
Returns
Type | Description |
---|---|
Task<string> | The URL of the uploaded object. |
UploadDirectoryAsync(string, string, string, string, CancellationToken)
Asynchronously uploads a directory to the specified Amazon S3 bucket.
Declaration
public Task UploadDirectoryAsync(string bucketName, string directory, string serverSideEncryptionMethod = null, string fileAcl = null, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
string | bucketName | The name of the S3 bucket. |
string | directory | The path of the local directory to upload. |
string | serverSideEncryptionMethod | The server-side encryption method (optional). |
string | fileAcl | The file access control for the uploaded files (optional). |
CancellationToken | cancellationToken | A token to cancel the asynchronous operation (optional). |
Returns
Type | Description |
---|---|
Task | A task representing the asynchronous operation. |