Skip to main content

ResQ.Storage

IStorageClient Interface

Interface for IPFS storage operations via Pinata.
public interface IStorageClient
Derived
PinataClient

Example

// Dependency injection registration
services.AddHttpClient<IStorageClient, PinataClient>();

// Usage
public class EvidenceService
{
    private readonly IStorageClient _storage;
    
    public EvidenceService(IStorageClient storage)
    {
        _storage = storage;
    }
    
    public async Task<string> StoreEvidenceAsync(byte[] imageData)
    {
        var result = await _storage.UploadAsync(
            imageData,
            "evidence.jpg",
            "image/jpeg",
            new Dictionary<string, string>
            {
                ["incidentId"] = "inc-001",
                ["droneId"] = "drn-001"
            });
        return result.Cid;
    }
}

Remarks

This interface defines the contract for storing and retrieving files on IPFS through the Pinata pinning service. Implementations handle the HTTP communication with Pinata’s API, authentication, and error handling. Files uploaded through this interface are automatically pinned to ensure they remain available on the IPFS network. The CID returned can be used to retrieve the file from any IPFS gateway.
Methods
GetAsync(string, CancellationToken)Retrieves file content by its IPFS CID.
GetGatewayUrl(string)Gets the gateway URL for accessing content by CID.
IsPinnedAsync(string, CancellationToken)Checks if a CID is currently pinned.
ListPinsAsync(string, int, CancellationToken)Lists pinned files with optional name prefix filtering.
UnpinAsync(string, CancellationToken)Unpins a file from Pinata.
UploadAsync(byte[], string, string, Dictionary<string,string>, CancellationToken)Uploads binary data to IPFS and pins it.
UploadAsync(Stream, string, string, Dictionary<string,string>, CancellationToken)Uploads a file stream to IPFS and pins it.