November 19, 2024

When developers need a file storage solution, AWS S3 is often the first option. However, AWS S3 can be expensive, complex, and often overkill for many projects. Enter Pinata, which offers a modern alternative: a straightforward Files API designed to simplify how developers manage file storage without breaking the bank.

What Makes Pinata’s Files API Special?

Pinata’s Files API is a centralized storage solution designed to complement its decentralized IPFS offerings. It provides developers with:

The Files API is ideal for developers who need traditional storage capabilities but with the developer-friendly ethos Pinata is known for.

A Ruby Solution for Pinata’s Files API

Pinata’s Files API is an incredible tool, but until now, Ruby developers lacked a dedicated library for leveraging its features. To address this gap, I’ve developed an open-source Ruby gem: Pinata Ruby.

This gem provides an elegant and intuitive way to interact with the Files API, enabling Ruby developers to upload, retrieve, and update their files effortlessly.

Getting Started with the Pinata Ruby Library

Installation

To install the gem, add it to your Gemfile:

gem 'pinata', '~> 1.0'

Then run bundle to complete the installation.

Configuration

Create your Pinata client with your Pinata API key:

require 'pinata'

client = Pinata::Client.new(jwt_key: 'your_api_jwt_key')

Authentication

Test your ability to connect to the Pinata API with the key:

client.authentication.test

Uploading a File

Uploading a file is as simple as:

result = client.files.upload_file(file: '/path/to/your/file')
puts "File stored with CID: #{result.cid}"

Listing Files

Access your stored files easily:

files = client.files.list
puts "Total # of files: #{files.data.size}"  

Updating File Name or Metadata

The gem also includes methods to update or delete files and folders:

result = client.files.update(file_id: "the_file_id", "name": "new_name_of_file")
puts "New name of file: #{result.name}"  

Try It Out

This library aims to make Pinata’s Files API more accessible to Ruby developers, saving time and effort while promoting scalable file storage solutions. It will grow to support more functionality provided by the API over time.

For full documentation, visit the GitHub repository: Pinata Ruby on GitHub. To understand more about the Files API, check out the official Pinata API docs.

Take your file storage to the next level with Pinata Ruby. Try it out, and build something amazing!

— Onyx