### Path Normalization for BunnyCDN Storage in C# Source: https://context7.com/bunnyway/bunnycdn.net.storage/llms.txt Illustrates the use of the NormalizePath utility in BunnyCDN.Net.Storage to format paths correctly for API calls. It handles different path styles, enforces directory or file formats, and validates that paths start with the storage zone name. ```csharp using BunnyCDN.Net.Storage; var storage = new BunnyCDNStorage("mystoragezonename", "my-api-access-key"); // Normalize a file path (removes leading slashes, fixes backslashes) string normalizedFile = storage.NormalizePath("/mystoragezonename/path/to/file.txt"); // Result: "mystoragezonename/path/to/file.txt" // Normalize and enforce as directory path (ensures trailing slash) string normalizedDir = storage.NormalizePath("/mystoragezonename/my-folder", isDirectory: true); // Result: "mystoragezonename/my-folder/" // Normalize and enforce as file path (throws if path ends with slash) string normalizedFilePath = storage.NormalizePath("/mystoragezonename/document.pdf", isDirectory: false); // Result: "mystoragezonename/document.pdf" // Handles Windows-style paths string windowsPath = storage.NormalizePath("\\mystoragezonename\\folder\\file.txt"); // Result: "mystoragezonename/folder/file.txt" // Path must start with storage zone name - this throws BunnyCDNStorageException try { storage.NormalizePath("/wrongzonename/file.txt"); } catch (BunnyCDNStorageException ex) { Console.WriteLine(ex.Message); // "Path validation failed. File path must begin with /mystoragezonename/." } ``` -------------------------------- ### List Objects in BunnyCDN Storage Source: https://github.com/bunnyway/bunnycdn.net.storage/blob/master/README.md Retrieves a list of all objects within a specified path in BunnyCDN storage. Returns a List collection, where each object contains details like GUID, path, size, and modification dates. ```csharp var objects = await bunnyCDNStorage.GetStorageObjectsAsync("/storagezonename/"); ``` -------------------------------- ### BunnyCDNStorage Client Initialization Source: https://context7.com/bunnyway/bunnycdn.net.storage/llms.txt Demonstrates how to create a new instance of the BunnyCDNStorage client for interacting with a specific storage zone, supporting different regions and custom HTTP handlers. ```APIDOC ## Initialize BunnyCDNStorage Client ### Description Creates a new instance of the BunnyCDNStorage client for interacting with a specific storage zone. The client handles authentication and configures the appropriate regional endpoint based on the storage zone's main replication region. ### Method Constructor ### Endpoint N/A (Client Initialization) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```csharp using BunnyCDN.Net.Storage; // Basic initialization with default region (Germany) var bunnyCDNStorage = new BunnyCDNStorage("mystoragezonename", "my-api-access-key"); // Initialize with specific region (ny = New York, sg = Singapore, de = Germany) var storageNY = new BunnyCDNStorage("mystoragezonename", "my-api-access-key", "ny"); var storageSG = new BunnyCDNStorage("mystoragezonename", "my-api-access-key", "sg"); // Initialize with custom HttpMessageHandler for advanced scenarios (mocking, logging, etc.) var customHandler = new HttpClientHandler(); var storageWithHandler = new BunnyCDNStorage("mystoragezonename", "my-api-access-key", "de", customHandler); ``` ### Response #### Success Response (200) N/A (Client Initialization) #### Response Example N/A ``` -------------------------------- ### Initialize BunnyCDNStorage Client (.NET) Source: https://context7.com/bunnyway/bunnycdn.net.storage/llms.txt Creates a new BunnyCDNStorage client instance for interacting with a specific storage zone. Supports default, regional, and custom HttpMessageHandler initializations. ```csharp using BunnyCDN.Net.Storage; // Basic initialization with default region (Germany) var bunnyCDNStorage = new BunnyCDNStorage("mystoragezonename", "my-api-access-key"); // Initialize with specific region (ny = New York, sg = Singapore, de = Germany) var storageNY = new BunnyCDNStorage("mystoragezonename", "my-api-access-key", "ny"); var storageSG = new BunnyCDNStorage("mystoragezonename", "my-api-access-key", "sg"); // Initialize with custom HttpMessageHandler for advanced scenarios (mocking, logging, etc.) var customHandler = new HttpClientHandler(); var storageWithHandler = new BunnyCDNStorage("mystoragezonename", "my-api-access-key", "de", customHandler); ``` -------------------------------- ### Initialize BunnyCDNStorage Client Source: https://github.com/bunnyway/bunnycdn.net.storage/blob/master/README.md Creates an instance of the BunnyCDNStorage client for interacting with the BunnyCDN Storage API. Requires storage zone name, API access key, and optionally the storage zone region and an HttpMessageHandler. ```csharp var bunnyCDNStorage = new BunnyCDNStorage("storagezonename", "MyAccessKey", "de"); ``` -------------------------------- ### Error Handling with BunnyCDN Storage Exceptions in C# Source: https://context7.com/bunnyway/bunnycdn.net.storage/llms.txt Demonstrates how to handle various BunnyCDN storage exceptions, including authentication, file not found, checksum errors, and general storage exceptions. This ensures robust error management in .NET applications interacting with BunnyCDN. ```csharp using BunnyCDN.Net.Storage; var storage = new BunnyCDNStorage("mystoragezonename", "my-api-access-key"); try { await storage.DownloadObjectAsync( "/mystoragezonename/files/document.pdf", "C:/downloads/document.pdf" ); } catch (BunnyCDNStorageAuthenticationException ex) { // Thrown when API key is invalid or doesn't have access to the storage zone Console.WriteLine($"Authentication failed: {ex.Message}"); } catch (BunnyCDNStorageFileNotFoundException ex) { // Thrown when the requested file or path doesn't exist Console.WriteLine($"File not found: {ex.Message}"); } catch (BunnyCDNStorageChecksumException ex) { // Thrown when upload checksum verification fails Console.WriteLine($"Checksum mismatch: {ex.Message}"); } catch (BunnyCDNStorageException ex) { // Base exception for all other BunnyCDN storage errors Console.WriteLine($"Storage error: {ex.Message}"); } ``` -------------------------------- ### Upload Local File Source: https://context7.com/bunnyway/bunnycdn.net.storage/llms.txt Uploads a file from the local filesystem to the storage zone, automatically creating directories and supporting checksum verification and content type overrides. ```APIDOC ## Upload Local File ### Description Uploads a file from the local filesystem to the storage zone. This method internally creates a FileStream and delegates to the stream-based upload method. Missing directories in the destination path are created automatically. ### Method `UploadAsync` ### Endpoint `POST /files/create` (Conceptual - actual endpoint handled by the library) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **localFilePath** (string) - Required - The absolute path to the local file to upload. - **destinationPath** (string) - Required - The full path where the file will be stored in the storage zone. - **validateChecksum** (bool) - Optional - If true, the library will automatically generate and verify the SHA256 checksum. - **sha256Checksum** (string) - Optional - A pre-computed SHA256 checksum for the content. Used for verification if provided. - **contentTypeOverride** (string) - Optional - Allows overriding the detected content type of the uploaded file. ### Request Example ```csharp using BunnyCDN.Net.Storage; var storage = new BunnyCDNStorage("mystoragezonename", "my-api-access-key"); // Basic file upload await storage.UploadAsync("C:/local/path/document.pdf", "/mystoragezonename/uploads/document.pdf"); // Upload with automatic checksum verification await storage.UploadAsync( "C:/local/path/important.zip", "/mystoragezonename/backups/important.zip", validateChecksum: true ); // Upload with pre-computed checksum and content type override await storage.UploadAsync( "C:/local/path/image.png", "/mystoragezonename/images/image.png", validateChecksum: true, sha256Checksum: "abc123...", contentTypeOverride: "image/png" ); ``` ### Response #### Success Response (200) - **Success** (bool) - Indicates if the upload was successful. #### Response Example ```json { "success": true } ``` ``` -------------------------------- ### List Storage Objects in C# Source: https://context7.com/bunnyway/bunnycdn.net.storage/llms.txt Retrieves a list of all files and directories at a specified path within a BunnyCDN storage zone. It returns StorageObject instances with metadata and allows filtering by file type. ```csharp using BunnyCDN.Net.Storage; using BunnyCDN.Net.Storage.Models; var storage = new BunnyCDNStorage("mystoragezonename", "my-api-access-key"); // List objects in the root of the storage zone List objects = await storage.GetStorageObjectsAsync("/mystoragezonename/"); // Process the returned objects foreach (var obj in objects) { Console.WriteLine($"Name: {obj.ObjectName}"); Console.WriteLine($"Full Path: {obj.FullPath}"); Console.WriteLine($"Is Directory: {obj.IsDirectory}"); Console.WriteLine($"Size (bytes): {obj.Length}"); Console.WriteLine($"Created: {obj.DateCreated}"); Console.WriteLine($"Last Modified: {obj.LastChanged}"); Console.WriteLine($"GUID: {obj.Guid}"); Console.WriteLine($"Storage Zone: {obj.StorageZoneName}"); Console.WriteLine($"Storage Zone ID: {obj.StorageZoneId}"); Console.WriteLine($"Server ID: {obj.ServerId}"); Console.WriteLine("---"); } // List objects in a subdirectory var subfolderObjects = await storage.GetStorageObjectsAsync("/mystoragezonename/images/"); // Filter only files (not directories) var filesOnly = objects.Where(o => !o.IsDirectory).ToList(); // Filter only directories var directoriesOnly = objects.Where(o => o.IsDirectory).ToList(); ``` -------------------------------- ### Upload Local File (.NET) Source: https://context7.com/bunnyway/bunnycdn.net.storage/llms.txt Uploads a local file to BunnyCDN storage, handling stream creation and directory creation. Supports checksum verification and content type overrides. ```csharp using BunnyCDN.Net.Storage; var storage = new BunnyCDNStorage("mystoragezonename", "my-api-access-key"); // Basic file upload await storage.UploadAsync("C:/local/path/document.pdf", "/mystoragezonename/uploads/document.pdf"); // Upload with automatic checksum verification await storage.UploadAsync( "C:/local/path/important.zip", "/mystoragezonename/backups/important.zip", validateChecksum: true ); // Upload with pre-computed checksum and content type override await storage.UploadAsync( "C:/local/path/image.png", "/mystoragezonename/images/image.png", validateChecksum: true, sha256Checksum: "abc123...", contentTypeOverride: "image/png" ); ``` -------------------------------- ### Download Object to Local File in C# Source: https://context7.com/bunnyway/bunnycdn.net.storage/llms.txt Downloads a file from BunnyCDN storage directly to a specified local file path. This method is efficient for large files and will create or overwrite the destination file. ```csharp using BunnyCDN.Net.Storage; var storage = new BunnyCDNStorage("mystoragezonename", "my-api-access-key"); // Download to local file await storage.DownloadObjectAsync( "/mystoragezonename/backups/database.bak", "C:/downloads/database.bak" ); // Download multiple files string[] filesToDownload = { "file1.txt", "file2.txt", "file3.txt" }; foreach (var file in filesToDownload) { await storage.DownloadObjectAsync( $"/mystoragezonename/documents/{file}", $"C:/downloads/{file}" ); } ``` -------------------------------- ### Upload Object from Stream Source: https://context7.com/bunnyway/bunnycdn.net.storage/llms.txt Uploads content from a stream to the specified path in the storage zone, with options for automatic checksum generation/verification and content type override. ```APIDOC ## Upload Object from Stream ### Description Uploads content from a stream to the specified path in the storage zone. If the target directory structure doesn't exist, it will be automatically created. Supports optional SHA256 checksum verification for ensuring data integrity during upload. ### Method `UploadAsync` ### Endpoint `POST /files/create` (Conceptual - actual endpoint handled by the library) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **stream** (Stream) - Required - The stream containing the content to upload. - **destinationPath** (string) - Required - The full path where the file will be stored in the storage zone. - **validateChecksum** (bool) - Optional - If true, the library will automatically generate and verify the SHA256 checksum. - **checksum** (string) - Optional - A pre-computed SHA256 checksum for the content. Used for verification if provided. - **contentTypeOverride** (string) - Optional - Allows overriding the detected content type of the uploaded file. ### Request Example ```csharp using BunnyCDN.Net.Storage; using System.IO; using System.Text; var storage = new BunnyCDNStorage("mystoragezonename", "my-api-access-key"); // Basic upload from stream using (var stream = new MemoryStream(Encoding.UTF8.GetBytes("Hello, World!"))) { await storage.UploadAsync(stream, "/mystoragezonename/documents/hello.txt"); } // Upload with automatic checksum generation and verification using (var stream = new MemoryStream(Encoding.UTF8.GetBytes("Important data"))) { await storage.UploadAsync(stream, "/mystoragezonename/secure/data.txt", validateChecksum: true); } // Upload with pre-computed SHA256 checksum using (var stream = new MemoryStream(Encoding.UTF8.GetBytes("Verified content"))) { string checksum = "d04b98f48e8f8bcc15c6ae5ac050801cd6dcfd428fb5f9e65c4e16e7807340fa"; await storage.UploadAsync(stream, "/mystoragezonename/verified/file.txt", checksum); } // Upload with content type override using (var stream = new MemoryStream(Encoding.UTF8.GetBytes("{\"key\": \"value\"}"))) { await storage.UploadAsync(stream, "/mystoragezonename/api/data.json", sha256Checksum: null, contentTypeOverride: "application/json"); } ``` ### Response #### Success Response (200) - **Success** (bool) - Indicates if the upload was successful. #### Response Example ```json { "success": true } ``` ``` -------------------------------- ### Download Object as Stream in C# Source: https://context7.com/bunnyway/bunnycdn.net.storage/llms.txt Downloads a file from BunnyCDN storage as a Stream, suitable for in-memory processing or streaming large files. It can be used to read content directly or copy to another destination. ```csharp using BunnyCDN.Net.Storage; using System.IO; var storage = new BunnyCDNStorage("mystoragezonename", "my-api-access-key"); // Download as stream and read content using (Stream stream = await storage.DownloadObjectAsStreamAsync("/mystoragezonename/documents/readme.txt")) { using (var reader = new StreamReader(stream)) { string content = await reader.ReadToEndAsync(); Console.WriteLine(content); } } // Stream to another destination (e.g., HTTP response) using (Stream stream = await storage.DownloadObjectAsStreamAsync("/mystoragezonename/files/data.bin")) { // Copy to another stream await stream.CopyToAsync(destinationStream); } ``` -------------------------------- ### Upload Object from Stream (.NET) Source: https://context7.com/bunnyway/bunnycdn.net.storage/llms.txt Uploads content from a stream to BunnyCDN storage, automatically creating directories if needed. Supports optional SHA256 checksum verification and content type overrides. ```csharp using BunnyCDN.Net.Storage; using System.IO; using System.Text; var storage = new BunnyCDNStorage("mystoragezonename", "my-api-access-key"); // Basic upload from stream using (var stream = new MemoryStream(Encoding.UTF8.GetBytes("Hello, World!"))) { await storage.UploadAsync(stream, "/mystoragezonename/documents/hello.txt"); } // Upload with automatic checksum generation and verification using (var stream = new MemoryStream(Encoding.UTF8.GetBytes("Important data"))) { await storage.UploadAsync(stream, "/mystoragezonename/secure/data.txt", validateChecksum: true); } // Upload with pre-computed SHA256 checksum using (var stream = new MemoryStream(Encoding.UTF8.GetBytes("Verified content"))) { string checksum = "d04b98f48e8f8bcc15c6ae5ac050801cd6dcfd428fb5f9e65c4e16e7807340fa"; await storage.UploadAsync(stream, "/mystoragezonename/verified/file.txt", checksum); } // Upload with content type override using (var stream = new MemoryStream(Encoding.UTF8.GetBytes("{\"key\": \"value\"}"))) { await storage.UploadAsync(stream, "/mystoragezonename/api/data.json", sha256Checksum: null, contentTypeOverride: "application/json"); } ``` -------------------------------- ### Upload Objects to BunnyCDN Storage Source: https://github.com/bunnyway/bunnycdn.net.storage/blob/master/README.md Uploads objects to BunnyCDN storage from a stream or a local file path. Supports automatic directory creation, checksum verification by providing a hash, or auto-generating the hash. Invalid hashes can be provided and will be auto-generated. ```csharp await bunnyCDNStorage.UploadAsync(stream, "/storagezonename/helloworld.txt"); await bunnyCDNStorage.UploadAsync("local/file/path/helloworld.txt", "/storagezonename/helloworld.txt"); await bunnyCDNStorage.UploadAsync(stream, "/storagezonename/helloworld.txt", "d04b98f48e8f8bcc15c6ae5ac050801cd6dcfd428fb5f9e65c4e16e7807340fa"); await bunnyCDNStorage.UploadAsync("/local/path/to/file.txt", "/storagezonename/helloworld.txt", "d04b98f48e8f8bcc15c6ae5ac050801cd6dcfd428fb5f9e65c4e16e7807340fa"); await bunnyCDNStorage.UploadAsync(stream, "/storagezonename/helloworld.txt", true); await bunnyCDNStorage.UploadAsync("/local/path/to/file.txt", "/storagezonename/helloworld.txt", true); await bunnyCDNStorage.UploadAsync(stream, "/storagezonename/helloworld.txt", true, "d04b98f48e8f8bcc15c6ae5ac050801cd6dcfd428fb5f9e65c4e16e7807340fa"); await bunnyCDNStorage.UploadAsync("/local/path/to/file.txt", "/storagezonename/helloworld.txt", true, "d04b98f48e8f8bcc15c6ae5ac050801cd6dcfd428fb5f9e65c4e16e7807340fa"); await bunnyCDNStorage.UploadAsync(stream, "/storagezonename/helloworld.txt", true, "invalidtobereplaced"); await bunnyCDNStorage.UploadAsync("/local/path/to/file.txt", "/storagezonename/helloworld.txt", true, "invalidtobereplaced"); ``` -------------------------------- ### Download Objects from BunnyCDN Storage Source: https://github.com/bunnyway/bunnycdn.net.storage/blob/master/README.md Downloads objects from BunnyCDN storage either as a stream or directly to a local file path. This operation allows for flexible retrieval of stored data. ```csharp await bunnyCDNStorage.DownloadObjectAsStreamAsync("/storagezonename/helloworld.txt"); await bunnyCDNStorage.DownloadObjectAsync("/storagezonename/helloworld.txt", "local/file/path/helloworld.txt"); ``` -------------------------------- ### Delete Object in C# Source: https://context7.com/bunnyway/bunnycdn.net.storage/llms.txt Deletes a file or directory from BunnyCDN storage. Deleting a directory recursively removes all its contents. The method returns a boolean indicating success and supports error handling for non-existent files. ```csharp using BunnyCDN.Net.Storage; var storage = new BunnyCDNStorage("mystoragezonename", "my-api-access-key"); // Delete a single file bool fileDeleted = await storage.DeleteObjectAsync("/mystoragezonename/uploads/old-file.txt"); Console.WriteLine($"File deleted: {fileDeleted}"); // Delete an entire directory (including all contents) bool dirDeleted = await storage.DeleteObjectAsync("/mystoragezonename/temp-folder/"); Console.WriteLine($"Directory deleted: {dirDeleted}"); // Delete with error handling try { await storage.DeleteObjectAsync("/mystoragezonename/nonexistent.txt"); } catch (BunnyCDNStorageFileNotFoundException ex) { Console.WriteLine($"File not found: {ex.Message}"); } ``` -------------------------------- ### Delete Objects from BunnyCDN Storage Source: https://github.com/bunnyway/bunnycdn.net.storage/blob/master/README.md Deletes specified objects from BunnyCDN storage. This operation supports deleting both individual files and entire directories, including their contents. ```csharp await bunnyCDNStorage.DeleteObjectAsync("/storagezonename/helloworld.txt"); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.