Skip to content

This is a simple c# wrapper for the Pinata api used for ipfs file management.

Notifications You must be signed in to change notification settings

SebastianDevelops/PinataNET

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PinataNET Documentation

Overview

PinataClient is a class for interacting with the Pinata API, allowing you to upload, pin, retrieve, update, and delete files on IPFS (InterPlanetary File System). The client requires a JWT (JSON Web Token) for authorization.

Installation

To use the PinataClient, ensure you have the following NuGet packages installed:

  • Newtonsoft.Json
  • HeyRed.Mime

Usage

Creating an Instance

To create an instance of PinataClient, you need to provide a JWT:

var pinataClient = new PinataClient("your_jwt_here");

Methods

PinFileToIPFSAsync

public async Task<PinFileResponse> PinFileToIPFSAsync(string filePath)

Pins a file to IPFS.

Parameters

  • filePath (string): The path of the file to be pinned.

Returns

  • PinFileResponse: A response containing the details of the pinned file.

Exceptions

  • Throws JsonException if the file pinning fails.

Example

var pinFileResponse = await pinataClient.PinFileToIPFSAsync("path/to/your/file.txt");

UploadFileAsync

public async Task<FileResponse> UploadFileAsync(Stream fileStream, string fileName, string groupId = "")

Uploads a file to Pinata.

Parameters

  • fileStream (Stream): The stream of the file to be uploaded.
  • fileName (string): The name of the file (including extension).
  • groupId (string, optional): An optional group ID for the file.

Returns

  • FileResponse: A response containing the upload details.

Exceptions

  • Throws JsonException if the upload fails.

Example

using (var fileStream = File.OpenRead("path/to/your/file.txt"))
{
    var fileResponse = await pinataClient.UploadFileAsync(fileStream, "file.txt");
}

GetFilesListAsync

public async Task<GetFilesListResponse> GetFilesListAsync()

Retrieves a list of files from Pinata.

Returns

  • GetFilesListResponse: A response containing a list of files.

Exceptions

  • Throws Exception if the retrieval fails.

Example

var filesListResponse = await pinataClient.GetFilesListAsync();

GetFileById

public async Task<FileResponse> GetFileById(string id)

Gets a file by its ID.

Parameters

  • id (string): The ID of the file to retrieve.

Returns

  • FileResponse: A response containing the file details.

Exceptions

  • Throws Exception if the retrieval fails.

Example

var fileResponse = await pinataClient.GetFileById("your_file_id");

UpdateFileNameAsync

public async Task<FileResponse> UpdateFileNameAsync(string id, string newName)

Updates the name of a specified file.

Parameters

  • id (string): The ID of the file to update.
  • newName (string): The new name for the file.

Returns

  • FileResponse: A response containing the updated file details.

Exceptions

  • Throws Exception if the update fails.

Example

var updatedFileResponse = await pinataClient.UpdateFileNameAsync("your_file_id", "new_file_name.txt");

DeleteFileAsync

public async Task<FileResponse> DeleteFileAsync(string id)

Deletes a specified file.

Parameters

  • id (string): The ID of the file to delete.

Returns

  • FileResponse: A response confirming the deletion of the file.

Exceptions

  • Throws Exception if the deletion fails.

Example

var deleteFileResponse = await pinataClient.DeleteFileAsync("your_file_id");

Error Handling

The PinataClient methods throw exceptions on failure, allowing you to handle errors gracefully in your application. Ensure that you wrap calls in try-catch blocks as needed.

try
{
    var fileResponse = await pinataClient.UploadFileAsync(fileStream, "file.txt");
}
catch (JsonException ex)
{
    Console.WriteLine($"Error: {ex.Message}");
}
catch (Exception ex)
{
    Console.WriteLine($"An unexpected error occurred: {ex.Message}");
}

Conclusion

The PinataClient class provides a simple interface for interacting with the Pinata API, enabling file management on IPFS. Use the methods provided to easily pin, upload, retrieve, update, and delete files.

About

This is a simple c# wrapper for the Pinata api used for ipfs file management.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages