/// <summary> /// Uploads a serialized object to storage (AWS S3) /// </summary> /// <param name="content">A serialized string to upload</param> /// <param name="storageKey">Unique key of data (Optional).</param> /// <returns><see cref="IStorageReference"/>- A general link to object in any storage service</returns> public IStorageReference PutData(string content, string storageKey = null) { var storageRef = new S3StorageReference(/*_bucketName,*/ GenerateKey(storageKey)); try { EnsureBucketExists(); var putRequest = new PutObjectRequest { BucketName = _bucketName, Key = storageRef.StorageKey, ContentBody = content }; if (UseEncryption) { //putRequest.ServerSideEncryptionCustomerMethod = ServerSideEncryptionCustomerMethod.AES256; //putRequest.ServerSideEncryptionCustomerProvidedKey = _base64Key; putRequest.ServerSideEncryptionMethod = ServerSideEncryptionMethod.AES256; } _client.PutObjectAsync(putRequest).Wait(); } catch (AmazonServiceException e) { throw new StorageManagerException("Failed to store the message content in an S3 object.", e); } catch (AmazonClientException e) { throw new StorageManagerException("Failed to store the message content in an S3 object.", e); } return(storageRef); }
/// <summary> /// Uploads serialized data asynchonously to AWS S3 /// </summary> /// <param name="content">Serialized data object</param> /// <param name="storageKey">Unique key of data (Optional)</param> /// <param name="cancellationToken">A cancellation token to control task execution</param> /// <returns>Task returning <see cref="IStorageReference"/> result</returns> public async Task <IStorageReference> PutDataAsync(string content, string storageKey = null, CancellationToken cancellationToken = default(CancellationToken)) { var storageRef = new S3StorageReference(/*_bucketName,*/ GenerateKey(storageKey)); try { await EnsureBucketExistsAsync(); var putRequest = new PutObjectRequest { BucketName = _bucketName, Key = storageRef.StorageKey, ContentBody = content }; if (UseEncryption) { //putRequest.ServerSideEncryptionCustomerMethod = ServerSideEncryptionCustomerMethod.AES256; //putRequest.ServerSideEncryptionCustomerProvidedKey = _base64Key; putRequest.ServerSideEncryptionMethod = ServerSideEncryptionMethod.AES256; } await _client.PutObjectAsync(putRequest, cancellationToken).ConfigureAwait(false); return(storageRef); } catch (AmazonServiceException e) { throw new StorageManagerException("Failed to store the content in an S3 object.", e); } catch (AmazonClientException e) { throw new StorageManagerException("Failed to store the message content.", e); } }