Pinning Files

This guide will walk you through the process of pinning files to IPFS using Filebase. We offer three methods for pinning files: our JavaScript SDK, our S3 Compatible API, and our web application dashboard. Choose the method that best suits your needs.

Using the JavaScript SDK

Installation

First, you need to install the Filebase SDK. You can do this using npm:

npm install @filebase/sdk

Uploading a File

Once you have the SDK installed, you can use it to pin files to IPFS. Here’s a simple example to get you started

import { ObjectManager } from "@filebase/sdk";
const objectManager = new ObjectManager(S3_KEY, S3_SECRET, {
  bucket: bucketName
});

const uploadedObject = await objectManager.upload(
  "my-object",
  Buffer.from("Hello World!")
);

console.log(uploadedObject);

API Reference

  • S3_KEY and S3_SECRET: Your Filebase API credentials.

  • objectManager.upload(): Pins the provided file to IPFS.

Uploading a Folder

You can also use the Filebase SDK to upload a folder. This will result in an IPFS folder being created.

import { ObjectManager } from "@filebase/sdk";
const fs = require('fs');
const rfs = require('recursive-fs');
const objectManager = new ObjectManager(S3_KEY, S3_SECRET, {
  bucket: bucketName
});

var filesArray = [];
var path = 'my-folder';
var {files} = await rfs.read(path)
files.forEach(file => {
    filesArray.push({path: file, content: fs.createReadStream(file)})
})

const uploadedObject = await objectManager.upload("my-first-directory", filesArray);
console.log(uploadedObject);

For more details, refer to the Filebase SDK documentation.

Using the S3 Compatible API

Authentication

Before you can start pinning files using the S3 Compatible API, you need to authenticate using your API key and secret.

Uploading a File

You can upload and pin files using standard S3 operations. Here’s an example using the AWS SDK for JavaScript:

const AWS = require('aws-sdk');

const s3 = new AWS.S3({
  endpoint: 'https://s3.filebase.com',
  region: 'us-east-1',
  signatureVersion: 'v4',
  accessKeyId: 'YOUR_API_KEY',
  secretAccessKey: 'YOUR_API_SECRET',
});

const params = {
  Bucket: 'YOUR_BUCKET_NAME',
  Key: 'path/to/your/file',
  Body: fs.readFileSync('path/to/your/file'),
};

const request = s3.putObject(params);
request.on('httpHeaders', (statusCode, headers) => {
    console.log(`CID: ${headers['x-amz-meta-cid']}`);
});
request.send();

API Reference

  • endpoint: Filebase S3 Compatible API endpoint.

  • Bucket: The name of your S3 bucket.

  • Key: The path where the file will be stored.

  • Body: The file content.

For more details, refer to the Filebase S3 API documentation.

Using the Web Application Dashboard

Step-by-Step Guide

  1. Login: Start by logging into your Filebase account.

  2. Navigate to the Buckets page: Once logged in, select Buckets from the menu on the left.

  3. Select Your Bucket: Choose the bucket where you want to pin your files.

  4. Upload Files: Click on the "Upload" button and select the files you want to pin.

Tips

  • Ensure your files are named appropriately before uploading.

  • You can monitor the pinning status directly from the dashboard.

Last updated