# 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:

```bash
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

```javascript
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.

```javascript
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](https://filebase.github.io/filebase-sdk/).

### 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:

```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](/api-documentation/s3-compatible-api.md).

### 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.\
   ![](/files/CSLyMlRpNCZDwuYBoKkA)
3. **Select Your Bucket**: Choose the bucket where you want to pin your files.\
   ![](/files/8VvdQXd7LzsvVyCgMmM4)
4. **Upload Files**: Click on the "Upload" button and select the files you want to pin.\
   ![](/files/V9sRQGXexTTWVp0LDJMm)

#### Tips

* Ensure your files are named appropriately before uploading.
* You can monitor the pinning status directly from the dashboard.

###


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.filebase.com/ipfs-pinning/pinning-files.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
