/

Upload & Download

ByteHide Storage provides multiple methods for uploading and downloading files, supporting various data formats and sources.

Upload Operations

Upload from File Path

Upload a file directly from your local filesystem:

// Upload file from local path
storage.FromFile("remote/document.txt", "path/to/local/document.txt");

// The file must exist at the specified path
if (File.Exists("myfile.txt"))
{
    storage.FromFile("remote/myfile.txt", "myfile.txt");
}

Upload String Content

Store text or string data directly:

// Upload simple string content
storage.Set("remote/message.txt", "Hello World");

// Upload JSON content
storage.Set("remote/config.json", @"{
    ""setting"": ""value"",
    ""enabled"": true
}");

Upload Byte Array

Upload raw binary data:

// Upload raw bytes
byte[] imageData = File.ReadAllBytes("image.jpg");
storage.Set("remote/image.jpg", imageData);

// Upload processed binary data
byte[] processedData = ProcessMyData();
storage.Set("remote/data.bin", processedData);

Upload from Assembly Resource

Upload embedded resources from your assembly:

// Get current assembly
var assembly = Assembly.GetExecutingAssembly();

// Upload embedded resource
storage.FromAssembly("remote/resource.txt", assembly, "MyNamespace.Resources.File.txt");

Download Operations

Save to Local File

Download and save file to local filesystem:

// Download to specific path
storage.SaveToDisk("remote/document.txt", "local/downloaded-document.txt");

// Ensure directory exists before downloading
Directory.CreateDirectory("downloads");
storage.SaveToDisk("remote/file.txt", "downloads/file.txt");

Get as String

Retrieve file content as string:

// Get text content
string content = storage.GetText("remote/message.txt");

// Get and parse JSON
string jsonConfig = storage.GetText("remote/config.json");
var config = JsonConvert.DeserializeObject(jsonConfig);

Get as Bytes

Download raw binary data:

// Get binary content
byte[] data = storage.GetBytes("remote/image.jpg");

// Process downloaded bytes
byte[] fileData = storage.GetBytes("remote/data.bin");
ProcessDownloadedData(fileData);

Get as Object

Directly deserialize JSON files to objects:

// Get and deserialize to specific type
var config = storage.Get<AppConfig>("remote/config.json");

// Get with type checking
var settings = storage.Get<Dictionary<string, string>>("remote/settings.json");

Basic Path Management

Organize files using paths and directories:

// Use subdirectories in paths
storage.Set("documents/2024/report.txt", content);

// Work within a specific directory
storage.In("documents").Set("report.txt", content); // Saves to "documents/report.txt"

Advanced Directory Management

For advanced directory operations and management, see our Directory Management guide.

Previous
Project Token