Skip to main content

Download File

Download File Function (Task)

Task<> IPFS.IpfsFunctionLibrary.DownloadFile(
IpfsHttpGatewayConfig ipfsHttpGatewayConfig,
IpfsAddress ipfsAddress,
string writeToFilepath,
bool createPathIfMissing,
bool overwriteExistingFile)

This function downloads a file from the IPFS network for the specified CID/Path. This function requires inputs as follows:

  • ipfsHttpGatewayConfig: Holds the URL of the gateway to send the request to.
  • ipfsAddress: Holds the CID and path of the file on IPFS network.
  • writeToFilepath: The filepath where the downloaded data is written to.
  • createPathIfMissing: Creates the filepath to where the downloaded data should be written to if it is missing.
  • overwriteExistingFile: If set to false and the file exists this function will abort with failure. Otherwise, an existing file will be overwritten.

The returned Response is a Task that holds data such as headers, status code, and body of the response of the HTTP request.

Task<(bool success, string errorMessage, HttpResponse response, string cid)>
info

If success is true that means that the response from the IPFS network was successful and writing file to disk to the specified path was also successful.

Download File Function (Delegate)

void IPFS.IpfsFunctionLibrary.DownloadFile(
IpfsHttpGatewayConfig ipfsHttpGatewayConfig,
IpfsAddress ipfsAddress,
string writeToFilepath,
bool createPathIfMissing,
bool overwriteExistingFile,
IpfsDownloadFileDelegate responseDelegate)

This is a wrapper function for the async implementation. It exists to provide the same functionality but using a delegate for handling responses.

delegate void IpfsDownloadFileDelegate(
bool success,
string errorMessage,
HttpResponse response)