public StorageMetadata( string bucket = null, long generation = 0, long metaGeneration = 0, string name = null, string path = null, long size = 0, string cacheControl = null, string contentDisposition = null, string contentEncoding = null, string contentLanguage = null, string contentType = null, IDictionary <string, string> customMetadata = null, string md5Hash = null, IStorageReference storageReference = null, DateTimeOffset updatedTime = default(DateTimeOffset), DateTimeOffset creationTime = default(DateTimeOffset)) { Bucket = bucket; Generation = generation; MetaGeneration = metaGeneration; Name = name; Path = path; Size = size; CacheControl = cacheControl; ContentLanguage = contentLanguage; ContentType = contentType; ContentDisposition = contentDisposition; ContentEncoding = contentEncoding; CustomMetadata = customMetadata; MD5Hash = md5Hash; StorageReference = storageReference; CreationTime = updatedTime; UpdatedTime = creationTime; }
/// <summary> /// Retrieves data from storage asynchronously /// </summary> /// <param name="storageReference"><see cref="IStorageReference"/></param> /// <param name="cancellationToken">a cancellation token to control task execution</param> /// <returns>Serialized object</returns> public async Task <string> GetDataAsync(IStorageReference storageReference, CancellationToken cancellationToken = default(CancellationToken)) { var getObjectRequest = new GetObjectRequest { BucketName = _bucketName, Key = GenerateKey(storageReference.GetStorageKey()) }; //if (UseEncryption) //{ // getObjectRequest.ServerSideEncryptionCustomerMethod = ServerSideEncryptionCustomerMethod.AES256; // getObjectRequest.ServerSideEncryptionCustomerProvidedKey = _base64Key; //} try { using (var getObjectResponse = await _client.GetObjectAsync(getObjectRequest, cancellationToken).ConfigureAwait(false)) { var streamReader = new StreamReader(getObjectResponse.ResponseStream); var text = streamReader.ReadToEnd(); return(text); } } catch (AmazonServiceException e) { throw new StorageManagerException("Failed to get the S3 object.", e); } catch (AmazonClientException e) { throw new StorageManagerException("Failed to get the S3 object.", e); } }
/// <summary> /// Retrieves serialized data from data storage (AWS S3) /// </summary> /// <param name="storageReference"><see cref="IStorageReference"/>- A general link to object in any storage service</param> /// <returns>A serialized object</returns> public string GetData(IStorageReference storageReference) { var getObjectRequest = new GetObjectRequest { BucketName = _bucketName, Key = GenerateKey(storageReference.GetStorageKey()) }; //if (UseEncryption) //{ // getObjectRequest.ServerSideEncryptionCustomerMethod = ServerSideEncryptionCustomerMethod.AES256; // getObjectRequest.ServerSideEncryptionCustomerProvidedKey = _base64Key; //} try { EnsureBucketExists(); using (var getObjectResponse = _client.GetObjectAsync(getObjectRequest).Result) { var streamReader = new StreamReader(getObjectResponse.ResponseStream); var text = streamReader.ReadToEnd(); return(text); } } catch (AmazonServiceException e) { throw new StorageManagerException("Failed to get the S3 object which contains the message payload.", e); } catch (AmazonClientException e) { throw new StorageManagerException("Failed to get the S3 object which contains the message payload.", e); } }
private static async Task TryDeleteAsync(IStorageReference reference) { try { await reference.DeleteAsync(); } catch (Exception e) { Console.WriteLine(e); } }
public ProjectManager(IProjectValidation projectValidation = null, ICollectionReference collectionReference = null, IStorageReference storageReference = null) { _projectValidation = projectValidation ?? (IProjectValidation)Splat.Locator.Current.GetService(typeof(IProjectValidation)); _collectionReference = collectionReference ?? CrossCloudFirestore.Current.Instance.GetCollection(FirestoreCollections.PROJECTS); _storageReference = storageReference ?? CrossFirebaseStorage.Current.Instance.RootReference; }
public UserManager(IUserValidation userValidation = null, ICollectionReference collectionReference = null, IStorageReference storageReference = null) { _userValidation = userValidation ?? (IUserValidation)Splat.Locator.Current.GetService(typeof(IUserValidation)); _collectionReference = collectionReference ?? CrossCloudFirestore.Current.Instance.GetCollection(FirestoreCollections.USERS); _storageReference = storageReference ?? CrossFirebaseStorage.Current.Instance.RootReference; }
internal void DeleteFromStorageTest([Frozen] string bucketName) { IStorageReference reference = Substitute.For <IStorageReference>(); var amazonS3 = Substitute.For <IAmazonS3>(); var deleted = false; amazonS3.When(x => x.DeleteObjectAsync(Arg.Any <DeleteObjectRequest>())).Do(x => { deleted = true; }); var storageManager = new S3StorageManager(bucketName, amazonS3); storageManager.DeleteData(reference); Assert.True(deleted); }
public async Task <byte[]> GetProfilePic(string userId) { byte[] picture = new byte[1024 * 1024]; IStorageReference reference = _storageReference.GetChild($"ProfilePics/{userId}.jpg"); try { picture = await reference.GetBytesAsync(1024 * 1024); } catch (FirebaseStorageException) { // possible do something here later?? } return(picture); }
public async Task <string> UploadProfilePic(string userId, Stream stream) { string message = ""; IStorageReference reference = _storageReference.GetChild($"ProfilePics/{userId}.jpg"); try { await reference.PutStreamAsync(stream); } catch (Exception e) { message = e.Message; } return(message); }
public async Task <string> DeleteImages(string id, List <string> images) { foreach (string fileName in images) { IStorageReference reference = _storageReference.GetChild($"Projects/{id}/{fileName}"); try { await reference.DeleteAsync(); } catch (FirebaseStorageException e) { return(e.Message); } } return(string.Empty); }
/// <summary> /// Removes data asynchronously from storage /// </summary> /// <param name="storageReference"><see cref="IStorageReference"/></param> /// <param name="cancellationToken">a cancellation token to control task execution</param> /// <returns>Task with no type</returns> public async Task DeleteDataAsync(IStorageReference storageReference, CancellationToken cancellationToken = default(CancellationToken)) { var deleteObjectRequest = new DeleteObjectRequest { BucketName = _bucketName, Key = GenerateKey(storageReference.GetStorageKey()) }; try { await _client.DeleteObjectAsync(deleteObjectRequest, cancellationToken).ConfigureAwait(false); } catch (AmazonServiceException e) { throw new AmazonClientException("Failed to delete the S3 object.", e); } catch (AmazonClientException e) { throw new AmazonClientException("Failed to delete the S3 object.", e); } }
/// <summary> /// Removes object from storage by storage reference /// </summary> /// <param name="storageReference"><see cref="IStorageReference"/>- A general link to object in any storage service</param> public void DeleteData(IStorageReference storageReference) { var deleteObjectRequest = new DeleteObjectRequest { BucketName = _bucketName, Key = GenerateKey(storageReference.GetStorageKey()) }; try { _client.DeleteObjectAsync(deleteObjectRequest).Wait(); } catch (AmazonServiceException e) { throw new StorageManagerException("Failed to delete the S3 object.", e); } catch (AmazonClientException e) { throw new StorageManagerException("Failed to delete the S3 object.", e); } }
public async Task <string> AddProjectImages(string id, List <Stream> images) { int i = 0; foreach (Stream stream in images) { IStorageReference reference = _storageReference.GetChild($"Projects/{id}/image-{i++}.jpg"); try { await reference.PutStreamAsync(stream); } catch (Exception e) { return(e.Message); } } return(string.Empty); }
public async Task <List <byte[]> > GetProjectImages(string projectId) { List <byte[]> images = new List <byte[]>(); int i = 0; bool error = false; IStorageReference reference = _storageReference.GetChild($"Projects/{projectId}"); while (!error) { try { images.Add(await reference.GetChild($"images-{i++}.jpg").GetBytesAsync(1024 * 1024)); } catch (FirebaseStorageException) { // Did not find file... does not exist error = true; } } return(images); }