Skip to main content

ResQ.Storage

PinataClient Class

Pinata IPFS client implementation of IStorageClient.
public class PinataClient : ResQ.Storage.IStorageClient
Inheritance System.Object → PinataClient Implements IStorageClient

Example

// Dependency injection registration
services.AddHttpClient<IStorageClient, PinataClient>();
services.Configure<PinataOptions>(options =>
{
    options.JwtToken = Environment.GetEnvironmentVariable("PINATA_JWT");
    options.MockMode = false;
});

// Usage
public class EvidenceService
{
    private readonly IStorageClient _storage;

    public EvidenceService(IStorageClient storage)
    {
        _storage = storage;
    }

    public async Task<string> UploadEvidenceAsync(byte[] imageData)
    {
        var result = await _storage.UploadAsync(imageData, "evidence.jpg", "image/jpeg");
        return result.Cid;
    }
}

Remarks

This client provides integration with the Pinata IPFS pinning service, allowing files to be uploaded to IPFS and pinned for guaranteed availability. The client supports both JWT token and API key/secret authentication methods. When MockMode is enabled, the client generates fake CIDs using SHA256 hashes of the content without making actual API calls. This is useful for testing and development without consuming Pinata credits. The client is designed to be used with dependency injection and requires an System.Net.Http.HttpClient configured with appropriate base address and authentication headers.
Methods
BuildResiliencePipeline()Builds the resilience pipeline with circuit breaker and timeout policies.
ConfigureHttpClient()Configures the HTTP client with base address, timeout, and authentication.
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.
MockUploadAsync(Stream, string, string, Dictionary<string,string>)Generates a mock upload result with a fake CID for testing purposes.
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.