Class IpfsClient
A client that allows access to the InterPlanetary File System (IPFS).
Inherited Members
Namespace: Ipfs.Http
Assembly: Ipfs.Http.Client.dll
Syntax
public class IpfsClient : IGenericApi, ICoreApi
Remarks
The API is based on the IPFS commands.
Constructors
| Improve this Doc View SourceIpfsClient()
Creates a new instance of the IpfsClient class and sets the default values.
Declaration
public IpfsClient()
Remarks
All methods of IpfsClient are thread safe. Typically, only one instance is required for an application.
IpfsClient(String)
Creates a new instance of the IpfsClient class and specifies the ApiUri. default values
Declaration
public IpfsClient(string host)
Parameters
| Type | Name | Description |
|---|---|---|
| String | host | The URL of the API host. For example "http://localhost:5001" or "http://ipv4.fiddler:5001". |
Fields
| Improve this Doc View SourceDefaultApiUri
The default URL to the IPFS HTTP API server.
Declaration
public static Uri DefaultApiUri
Field Value
| Type | Description |
|---|---|
| Uri | The default is "http://localhost:5001". |
Remarks
The environment variable "IpfsHttpApi" overrides this value.
Properties
| Improve this Doc View SourceApiUri
The URL to the IPFS API server. The default is "http://localhost:5001".
Declaration
public Uri ApiUri { get; set; }
Property Value
| Type | Description |
|---|---|
| Uri |
Bitswap
Declaration
public IBitswapApi Bitswap { get; }
Property Value
| Type | Description |
|---|---|
| IBitswapApi |
Block
Declaration
public IBlockApi Block { get; }
Property Value
| Type | Description |
|---|---|
| IBlockApi |
BlockRepository
Declaration
public IBlockRepositoryApi BlockRepository { get; }
Property Value
| Type | Description |
|---|---|
| IBlockRepositoryApi |
Bootstrap
Declaration
public IBootstrapApi Bootstrap { get; }
Property Value
| Type | Description |
|---|---|
| IBootstrapApi |
Config
Declaration
public IConfigApi Config { get; }
Property Value
| Type | Description |
|---|---|
| IConfigApi |
Dag
Declaration
public IDagApi Dag { get; }
Property Value
| Type | Description |
|---|---|
| IDagApi |
Dht
Declaration
public IDhtApi Dht { get; }
Property Value
| Type | Description |
|---|---|
| IDhtApi |
Dns
Declaration
public IDnsApi Dns { get; }
Property Value
| Type | Description |
|---|---|
| IDnsApi |
FileSystem
Declaration
public IFileSystemApi FileSystem { get; }
Property Value
| Type | Description |
|---|---|
| IFileSystemApi |
Generic
Declaration
public IGenericApi Generic { get; }
Property Value
| Type | Description |
|---|---|
| IGenericApi |
Key
Declaration
public IKeyApi Key { get; }
Property Value
| Type | Description |
|---|---|
| IKeyApi |
Name
Declaration
public INameApi Name { get; }
Property Value
| Type | Description |
|---|---|
| INameApi |
Object
Declaration
public IObjectApi Object { get; }
Property Value
| Type | Description |
|---|---|
| IObjectApi |
Pin
Declaration
public IPinApi Pin { get; }
Property Value
| Type | Description |
|---|---|
| IPinApi |
PubSub
Declaration
public IPubSubApi PubSub { get; }
Property Value
| Type | Description |
|---|---|
| IPubSubApi |
Stats
Declaration
public IStatsApi Stats { get; }
Property Value
| Type | Description |
|---|---|
| IStatsApi |
Swarm
Declaration
public ISwarmApi Swarm { get; }
Property Value
| Type | Description |
|---|---|
| ISwarmApi |
TrustedPeers
The list of peers that are initially trusted by IPFS.
Declaration
public TrustedPeerCollection TrustedPeers { get; }
Property Value
| Type | Description |
|---|---|
| TrustedPeerCollection |
Remarks
This is equilivent to ipfs bootstrap list.
UserAgent
The value of HTTP User-Agent header sent to the API server.
Declaration
public string UserAgent { get; set; }
Property Value
| Type | Description |
|---|---|
| String | The default value is "net-ipfs/M.N", where M is the major and N is minor version numbers of the assembly. |
Methods
| Improve this Doc View SourceDoCommandAsync(String, CancellationToken, String, String[])
Perform an IPFS API command returning a string.
Declaration
public Task<string> DoCommandAsync(string command, CancellationToken cancel, string arg = null, params string[] options)
Parameters
| Type | Name | Description |
|---|---|---|
| String | command | The IPFS API command, such as "file/ls". |
| CancellationToken | cancel | Is used to stop the task. When cancelled, the TaskCanceledException is raised. |
| String | arg | The optional argument to the command. |
| String[] | options | The optional flags to the command. |
Returns
| Type | Description |
|---|---|
| Task<String> | A string representation of the command's result. |
Exceptions
| Type | Condition |
|---|---|
| HttpRequestException | When the IPFS server indicates an error. |
DoCommandAsync<T>(String, CancellationToken, String, String[])
Perform an IPFS API command returning a specific Type.
Declaration
public Task<T> DoCommandAsync<T>(string command, CancellationToken cancel, string arg = null, params string[] options)
Parameters
| Type | Name | Description |
|---|---|---|
| String | command | The IPFS API command, such as "file/ls". |
| CancellationToken | cancel | Is used to stop the task. When cancelled, the TaskCanceledException is raised. |
| String | arg | The optional argument to the command. |
| String[] | options | The optional flags to the command. |
Returns
| Type | Description |
|---|---|
| Task<T> | A |
Type Parameters
| Name | Description |
|---|---|
| T | The Type of object to return. |
Remarks
The command's response is converted to T using
JsonConvert.
Exceptions
| Type | Condition |
|---|---|
| HttpRequestException | When the IPFS server indicates an error. |
DownloadAsync(String, CancellationToken, String, String[])
Perform an IPFS API command returning a Stream.
Declaration
public Task<Stream> DownloadAsync(string command, CancellationToken cancel, string arg = null, params string[] options)
Parameters
| Type | Name | Description |
|---|---|---|
| String | command | The IPFS API command, such as "file/ls". |
| CancellationToken | cancel | Is used to stop the task. When cancelled, the TaskCanceledException is raised. |
| String | arg | The optional argument to the command. |
| String[] | options | The optional flags to the command. |
Returns
| Type | Description |
|---|---|
| Task<Stream> | A Stream containing the command's result. |
Exceptions
| Type | Condition |
|---|---|
| HttpRequestException | When the IPFS server indicates an error. |
DownloadBytesAsync(String, CancellationToken, String, String[])
Perform an IPFS API command returning a a byte array.
Declaration
public Task<byte[]> DownloadBytesAsync(string command, CancellationToken cancel, string arg = null, params string[] options)
Parameters
| Type | Name | Description |
|---|---|---|
| String | command | The IPFS API command, such as "file/ls". |
| CancellationToken | cancel | Is used to stop the task. When cancelled, the TaskCanceledException is raised. |
| String | arg | The optional argument to the command. |
| String[] | options | The optional flags to the command. |
Returns
| Type | Description |
|---|---|
| Task<Byte[]> | A byte array containing the command's result. |
Exceptions
| Type | Condition |
|---|---|
| HttpRequestException | When the IPFS server indicates an error. |
IdAsync(MultiHash, CancellationToken)
Declaration
public Task<Peer> IdAsync(MultiHash peer = null, CancellationToken cancel = default(CancellationToken))
Parameters
| Type | Name | Description |
|---|---|---|
| MultiHash | peer | |
| CancellationToken | cancel |
Returns
| Type | Description |
|---|---|
| Task<Peer> |
PingAsync(MultiAddress, Int32, CancellationToken)
Declaration
public Task<IEnumerable<PingResult>> PingAsync(MultiAddress address, int count = 10, CancellationToken cancel = default(CancellationToken))
Parameters
| Type | Name | Description |
|---|---|---|
| MultiAddress | address | |
| Int32 | count | |
| CancellationToken | cancel |
Returns
| Type | Description |
|---|---|
| Task<IEnumerable<PingResult>> |
PingAsync(MultiHash, Int32, CancellationToken)
Declaration
public Task<IEnumerable<PingResult>> PingAsync(MultiHash peer, int count = 10, CancellationToken cancel = default(CancellationToken))
Parameters
| Type | Name | Description |
|---|---|---|
| MultiHash | peer | |
| Int32 | count | |
| CancellationToken | cancel |
Returns
| Type | Description |
|---|---|
| Task<IEnumerable<PingResult>> |
PostDownloadAsync(String, CancellationToken, String, String[])
Post an IPFS API command returning a stream.
Declaration
public Task<Stream> PostDownloadAsync(string command, CancellationToken cancel, string arg = null, params string[] options)
Parameters
| Type | Name | Description |
|---|---|---|
| String | command | The IPFS API command, such as "file/ls". |
| CancellationToken | cancel | Is used to stop the task. When cancelled, the TaskCanceledException is raised. |
| String | arg | The optional argument to the command. |
| String[] | options | The optional flags to the command. |
Returns
| Type | Description |
|---|---|
| Task<Stream> | A Stream containing the command's result. |
Exceptions
| Type | Condition |
|---|---|
| HttpRequestException | When the IPFS server indicates an error. |
ResolveAsync(String, Boolean, CancellationToken)
Declaration
public Task<string> ResolveAsync(string name, bool recursive = true, CancellationToken cancel = default(CancellationToken))
Parameters
| Type | Name | Description |
|---|---|---|
| String | name | |
| Boolean | recursive | |
| CancellationToken | cancel |
Returns
| Type | Description |
|---|---|
| Task<String> |
ShutdownAsync()
Declaration
public Task ShutdownAsync()
Returns
| Type | Description |
|---|---|
| Task |
Upload2Async(String, CancellationToken, Stream, String, String[])
Perform an IPFS API command that requires uploading of a "file".
Declaration
public Task<Stream> Upload2Async(string command, CancellationToken cancel, Stream data, string name, params string[] options)
Parameters
| Type | Name | Description |
|---|---|---|
| String | command | The IPFS API command, such as "add". |
| CancellationToken | cancel | Is used to stop the task. When cancelled, the TaskCanceledException is raised. |
| Stream | data | A Stream containing the data to upload. |
| String | name | The name associated with the |
| String[] | options | The optional flags to the command. |
Returns
| Type | Description |
|---|---|
| Task<Stream> | A task that represents the asynchronous operation. The task's value is the HTTP response as a Stream. |
Exceptions
| Type | Condition |
|---|---|
| HttpRequestException | When the IPFS server indicates an error. |
UploadAsync(String, CancellationToken, Byte[], String[])
TODO
Declaration
public Task<string> UploadAsync(string command, CancellationToken cancel, byte[] data, params string[] options)
Parameters
| Type | Name | Description |
|---|---|---|
| String | command | |
| CancellationToken | cancel | |
| Byte[] | data | |
| String[] | options |
Returns
| Type | Description |
|---|---|
| Task<String> |
UploadAsync(String, CancellationToken, Stream, String, String[])
Perform an IPFS API command that requires uploading of a "file".
Declaration
public Task<string> UploadAsync(string command, CancellationToken cancel, Stream data, string name, params string[] options)
Parameters
| Type | Name | Description |
|---|---|---|
| String | command | The IPFS API command, such as "add". |
| CancellationToken | cancel | Is used to stop the task. When cancelled, the TaskCanceledException is raised. |
| Stream | data | A Stream containing the data to upload. |
| String | name | The name associated with the |
| String[] | options | The optional flags to the command. |
Returns
| Type | Description |
|---|---|
| Task<String> | A task that represents the asynchronous operation. The task's value is the HTTP response as a string. |
Exceptions
| Type | Condition |
|---|---|
| HttpRequestException | When the IPFS server indicates an error. |
VersionAsync(CancellationToken)
Declaration
public Task<Dictionary<string, string>> VersionAsync(CancellationToken cancel = default(CancellationToken))
Parameters
| Type | Name | Description |
|---|---|---|
| CancellationToken | cancel |
Returns
| Type | Description |
|---|---|
| Task<Dictionary<String, String>> |