public override async Task SaveAsync(BlobProviderSaveArgs args) { var container = await GetOrCreateContainerAsync(args.ContainerName, args.CancellationToken); var blob = await DatabaseBlobRepository.FindAsync( container.Id, args.BlobName, args.CancellationToken ); var content = await args.BlobStream.GetAllBytesAsync(args.CancellationToken); if (blob != null) { if (!args.OverrideExisting) { throw new BlobAlreadyExistsException( $"Saving BLOB '{args.BlobName}' does already exists in the container '{args.ContainerName}'! Set {nameof(args.OverrideExisting)} if it should be overwritten."); } blob.SetContent(content); await DatabaseBlobRepository.UpdateAsync(blob, autoSave : true); } else { blob = new DatabaseBlob(GuidGenerator.Create(), container.Id, args.BlobName, content, CurrentTenant.Id); await DatabaseBlobRepository.InsertAsync(blob, autoSave : true); } }
public override async Task <Stream> GetOrNullAsync(BlobProviderGetArgs args) { var container = await DatabaseBlobContainerRepository.FindAsync( args.ContainerName, args.CancellationToken ); if (container == null) { return(null); } var blob = await DatabaseBlobRepository.FindAsync( container.Id, args.BlobName, args.CancellationToken ); if (blob == null) { return(null); } return(new MemoryStream(blob.Content)); }