public void PutObject() { var bucketName = "ravendb"; var key = "testKey"; using (var client = new RavenAwsS3Client("<aws_access_key>", "<aws_secret_key>", "<aws_region_for_bucket>")) { client.PutObject(bucketName, key, new MemoryStream(Encoding.UTF8.GetBytes("321")), new Dictionary <string, string> { { "property1", "value1" }, { "property2", "value2" } }, 60 * 60); var @object = client.GetObject(bucketName, key); Assert.NotNull(@object); using (var reader = new StreamReader(@object.Data)) Assert.Equal("321", reader.ReadToEnd()); var property1 = @object.Metadata.Keys.Single(x => x.Contains("property1")); var property2 = @object.Metadata.Keys.Single(x => x.Contains("property2")); Assert.Equal("value1", @object.Metadata[property1]); Assert.Equal("value2", @object.Metadata[property2]); } }
public async Task put_object(string region) { var bucketName = $"testing-{Guid.NewGuid()}"; var key = $"test-key-{Guid.NewGuid()}"; using (var client = new RavenAwsS3Client(AwsAccessKey, AwsSecretKey, region, bucketName)) { // make sure that the bucket doesn't exist await client.DeleteBucket(); try { await client.PutBucket(); var value1 = Guid.NewGuid().ToString(); var value2 = Guid.NewGuid().ToString(); await client.PutObject(key, new MemoryStream(Encoding.UTF8.GetBytes("231")), new Dictionary <string, string> { { "property1", value1 }, { "property2", value2 } }); // can't delete a bucket with existing objects var e = await Assert.ThrowsAsync <StorageException>(async() => await client.DeleteBucket()); Assert.True(e.Message.Contains("The bucket you tried to delete is not empty")); var @object = await client.GetObject(key); Assert.NotNull(@object); using (var reader = new StreamReader(@object.Data)) Assert.Equal("231", reader.ReadToEnd()); var property1 = @object.Metadata.Keys.Single(x => x.Contains("property1")); var property2 = @object.Metadata.Keys.Single(x => x.Contains("property2")); Assert.Equal(value1, @object.Metadata[property1]); Assert.Equal(value2, @object.Metadata[property2]); } finally { await client.DeleteObject(key); await client.DeleteBucket(); } } }
// ReSharper disable once InconsistentNaming private static async Task PutObject(string region, int sizeInMB, bool testBlobKeyAsFolder, UploadType uploadType) { var bucketName = $"testing-{Guid.NewGuid()}"; var key = testBlobKeyAsFolder == false? Guid.NewGuid().ToString() : $"{Guid.NewGuid()}/folder/testKey"; var uploadProgress = new UploadProgress(); var maxUploadPutObjectInBytesSetter = ExpressionHelper.CreateFieldSetter <RavenAwsS3Client, int>("MaxUploadPutObjectSizeInBytes"); var minOnePartUploadSizeLimitInBytesSetter = ExpressionHelper.CreateFieldSetter <RavenAwsS3Client, int>("MinOnePartUploadSizeLimitInBytes"); using (var client = new RavenAwsS3Client(AwsAccessKey, AwsSecretKey, region, bucketName, uploadProgress)) { maxUploadPutObjectInBytesSetter(client, 10 * 1024 * 1024); // 10MB minOnePartUploadSizeLimitInBytesSetter(client, 7 * 1024 * 1024); // 7MB // make sure that the bucket doesn't exist await client.DeleteBucket(); try { await client.PutBucket(); var value1 = Guid.NewGuid().ToString(); var value2 = Guid.NewGuid().ToString(); var sb = new StringBuilder(); for (var i = 0; i < sizeInMB * 1024 * 1024; i++) { sb.Append("a"); } long streamLength; using (var memoryStream = new MemoryStream(Encoding.UTF8.GetBytes(sb.ToString()))) { streamLength = memoryStream.Length; await client.PutObject(key, memoryStream, new Dictionary <string, string> { { "property1", value1 }, { "property2", value2 } }); } var @object = await client.GetObject(key); Assert.NotNull(@object); using (var reader = new StreamReader(@object.Data)) Assert.Equal(sb.ToString(), reader.ReadToEnd()); var property1 = @object.Metadata.Keys.Single(x => x.Contains("property1")); var property2 = @object.Metadata.Keys.Single(x => x.Contains("property2")); Assert.Equal(value1, @object.Metadata[property1]); Assert.Equal(value2, @object.Metadata[property2]); Assert.Equal(UploadState.Done, uploadProgress.UploadState); Assert.Equal(uploadType, uploadProgress.UploadType); Assert.Equal(streamLength, uploadProgress.TotalInBytes); Assert.Equal(streamLength, uploadProgress.UploadedInBytes); } finally { await client.DeleteObject(key); await client.DeleteBucket(); } } }
protected override async Task <ZipArchive> GetZipArchive(string filePath) { var blob = await _client.GetObject(filePath); return(new ZipArchive(blob.Data, ZipArchiveMode.Read)); }
protected override async Task <Stream> GetStream(string path) { var blob = await _client.GetObject(path); return(blob.Data); }