/

Handling files

Uploading an Image with Encryption and Compression using Embedded Resources Helper

This section shows how to load an image file from the project's embedded resources. ResourceManagerHelper.GetResourceAsBytes()

var image = ResourceManagerHelper.GetResourceAsBytes(Assembly.GetExecutingAssembly(), "Sample.Resources.Images.photo0.jpg");

if (image == null || image.Length == 0)
{
    Console.WriteLine("Failed to load the image from resources.");
    return;
}
bool uploaded = storage
    .In("<bucket_name>/images")
    .Set("photo.jpg", image);

With Async mode:

bool uploaded = await storage
	.In("<bucket_name>/images")
	.SetAsync("photo.jpg", image).Result;

Uploading an Image from assembly

This section demonstrates how to upload an image to the storage bucket from the assembly. FromAssembly()

bool uploaded = storage
     .In("<bucket_name>/images")
     .FromAssembly("photo.jpg", Assembly.GetExecutingAssembly(), "<my_project_>.Resources.<path_to_image>");

Uploading from a file

This section demonstrates how to upload a file to the storage bucket from the local file system. FromFile()

bool uploaded = storage
	 .In("<bucket_name>/images")
	 .FromFile("photo.jpg", "<path_to_image>/photo.jpg");
bool uploaded = storage
	 .In("<bucket_name>/texts")
	 .FromFile("file.txt", "<path_to_file>/file.txt");

Uploading a File with Compression

This section demonstrates how to upload a file with compression. Compress()

bool uploaded = storage
	 .In("<bucket_name>/images")
     .Compress()
	 .FromAssembly("photo.jpg", Assembly.GetExecutingAssembly(), "<my_project_>.Resources.<image_path>");
bool uploaded = storage
	 .In("<bucket_name>/images")
	 .Compress()
	 .FromFile("photo.jpg", "<path_to_image>/photo.jpg");
bool uploaded = storage
	 .In("<bucket_name>/texts")
     .Compress()
	 .FromFile("file.txt", "<path_to_file>/file.txt");

Uploading a File with Encryption

This section demonstrates how to upload a file with encryption. Encrypt()

bool uploaded = storage
	 .In("<bucket_name>/images")
	 .Encrypt()
	 .FromAssembly("photo.jpg", Assembly.GetExecutingAssembly(), "<my_project_>.Resources.<image_path>");
bool uploaded = storage
	 .In("<bucket_name>/images")
	 .Encrypt()
	 .FromFile("photo.jpg", "<path_to_image>/photo.jpg");
bool uploaded = storage
	 .In("<bucket_name>/texts")
	 .Encrypt()
	 .FromFile("file.txt", "<path_to_file>/file.txt");

Uploading a File with Encryption and Compression

This section demonstrates how to upload a file with encryption and compression. Encrypt() and Compress()

bool uploaded = storage
	 .In("<bucket_name>/images")
	 .Compress()
	 .Encrypt()
	 .FromAssembly("photo.jpg", Assembly.GetExecutingAssembly(), "<my_project_>.Resources.<image_path>");
bool uploaded = storage
     .In("<bucket_name>/images")
     .Compress()
     .Encrypt()
     .FromFile("photo.jpg", "<path_to_image>/photo.jpg");
bool uploaded = storage
	 .In("<bucket_name>/texts")
	 .Compress()
	 .Encrypt()
	 .FromFile("file.txt", "<path_to_file>/file.txt");

Uploading a File with Quantum Encryption and Compression

This section demonstrates how to upload a file with quantum encryption and compression. EncryptWithQuantum()

bool uploaded = storage
	 .In("<bucket_name>/images")
	 .EncryptWithQuantum()
	 .Compress()
	 .FromAssembly("photo.jpg", Assembly.GetExecutingAssembly(), "<my_project_>.Resources.<image_path>");
bool uploaded = storage
	 .In("<bucket_name>/images")
	 .EncryptWithQuantum()
	 .Compress()
	 .FromFile("photo.jpg", "<path_to_image>/photo.jpg");
bool uploaded = storage
	 .In("<bucket_name>/texts")
	 .EncryptWithQuantum()
	 .Compress()
	 .FromFile("file.txt", "<path_to_file>/file.txt");

Uploading a Large Text File

Upload a large text file and apply compression and encryption. The maximum file size is 5 GB.

var largeText = Encoding.UTF8.GetBytes(new string('A', 10000000));
storage
    .In("<bucket_name>/texts")
    .Compress()
    .Encrypt()
    .Set("payload.txt", largeText);

With Quantum Encryption

var largeText = Encoding.UTF8.GetBytes(new string('A', 10000000));
storage
	.In("<bucket_name>/texts")
	.Compress()
	.EncryptWithQuantum()
	.Set("payload.txt", largeText);

Downloading an Image and Saving to Disk

storage
    .In("<bucket_name>/images")
    .SaveToDisk("photo.jpg", "<path_to_downloaded_image>/photo.jpg");

Downloading Text Files

Download a text file and save it to disk.

storage
    .In("<bucket_name>/texts")
    .SaveToDisk("payload.txt", "<path_to_downloaded_text>/payload.txt");

Or

storage
    .SaveToDisk("<bucket_name>/texts/payload.txt", "<path_to_downloaded_text>/payload.txt");

Download the text file as a string.

string text = storage
               .In("<bucket_name>/texts")
               .GetText("payload.txt");

Or

string text = storage
               .GetText("<bucket_name>/texts/payload.txt");

Async

string text = await storage
			 .In("<bucket_name>/texts")
			 .GetTextAsync("payload.txt").Result;

Download the text file as a byte array.

byte[] data = storage
               .In("<bucket_name>/texts")
               .GetBytes("payload.txt");

Or

byte[] data = storage
               .GetBytes("<bucket_name>/texts/payload.txt");

Async

string text = await storage
			 .In("<bucket_name>/texts")
			 .GetBytesAsync("payload.txt").Result;

Uploading and Downloading JSON Data

Upload a JSON string as a text file.

const string json = "{\\"name\\":\\"John Doe\\",\\"age\\":30}";
var uploaded = storage
                .In("<bucket_name>/models")
                .Compress()
                .Encrypt()
                .Set("json.txt", json);
// Define a simple class Foo for demonstration purposes
private class Foo
{
    private string Name { get; }
    private int Age { get; }

    public Foo(string name, int age)
    {
        Name = name;
        Age = age;
    }

    public override string ToString() => $"Name: {Name}, Age: {Age}";
}

Download the JSON and deserialize it to a custom Foo object.

var data = storage
             .In("<bucket_name>/models")
             .Get<Foo>("json.txt");

Async

var data = await storage
			 .In("<bucket_name>/models")
			 .GetAsync<Foo>("json.txt").Result;

Output

Name: John Doe, Age: 30

Download the JSON as a string.

string text = storage
             .In("<bucket_name>/models")
             .GetText("json.txt");

Async

string text = await storage
			 .In("<bucket_name>/models")
			 .GetTextAsync("json.txt").Result;

Output

{"name":"John Doe","age":30}

Notes

The compression and encryption methods can be chained in any order. The order of the methods does not matter.

storage
	.In("<bucket_name>/images")
	.Encrypt()
	.Compress()
	.FromAssembly("photo.jpg", Assembly.GetExecutingAssembly(), "<my_project_>.Resources.<image_path>");
storage
	.In("<bucket_name>/images")
	.Compress()
	.Encrypt()
	.FromAssembly("photo.jpg", Assembly.GetExecutingAssembly(), "<my_project_>.Resources.<image_path>");

If encryption and quantum encryption are used together, it will be applied the last one.

Encryption

storage
	.In("<bucket_name>/images")
	.EncryptWithQuantum()
	.Encrypt()
	.FromAssembly("photo.jpg", Assembly.GetExecutingAssembly(), "<my_project_>.Resources.<image_path>");

Quantum Encryption:

storage
	.In("<bucket_name>/images")
	.Encrypt()
	.EncryptWithQuantum()
	.FromAssembly("photo.jpg", Assembly.GetExecutingAssembly(), "<my_project_>.Resources.<image_path>");

The compressed files are detected automatically and decompressed during download.

The encrypted files are detected automatically and decrypted during download.

Previous
Initialize