Skip to main content

ResQ.Storage.PinataClient

PinataClient.GetAsync(string, CancellationToken) Method

Retrieves file content by its IPFS CID.
public System.Threading.Tasks.Task<System.IO.Stream> GetAsync(string cid, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));

Parameters

cid System.String The IPFS Content Identifier of the file to retrieve. cancellationToken System.Threading.CancellationToken Cancellation token for the operation. Implements GetAsync(string, CancellationToken)

Returns

System.Threading.Tasks.Task<System.IO.Stream>
A stream containing the file content.

Exceptions

System.ArgumentNullException
Thrown when cid is null or empty.
System.InvalidOperationException
Thrown when the file cannot be retrieved.
System.OperationCanceledException
Thrown when the operation is cancelled.

Example

using var stream = await storage.GetAsync("Qmabc123...");
using var fileStream = File.Create("downloaded.jpg");
await stream.CopyToAsync(fileStream);

Remarks

The content is retrieved through the configured IPFS gateway. The caller is responsible for disposing the returned stream. In mock mode, returns a mock stream.