# @catalogworks/filebase-storage-js

> JS SDK to interact with Filebase

Latest version **0.1.6** (published 2022-12-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install @catalogworks/filebase-storage-js
pnpm add @catalogworks/filebase-storage-js
yarn add @catalogworks/filebase-storage-js
bun add @catalogworks/filebase-storage-js
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.6 |
| Published | 2022-12-25 |
| First published | 2022-12-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 35.8 KB |
| Known vulnerabilities | 0 (+24 in 2 direct dependencies) |
| Install scripts | no |
| Author | @catalogworks |
| Maintainers | reefloretto, bretth18 |

## Links

- npm: https://www.npmjs.com/package/@catalogworks/filebase-storage-js
- Repository: https://github.com/catalogworks/filebase-storage-js
- Homepage: https://github.com/catalogworks/filebase-storage-js#readme
- Issues: https://github.com/catalogworks/filebase-storage-js/issues
- npm.io page: https://npm.io/package/@catalogworks/filebase-storage-js

## Dependencies (4)

- [axios](https://npm.io/package/axios.md) ^0.21.1
- [aws-sdk](https://npm.io/package/aws-sdk.md) ^2.989.0
- [multiformats](https://npm.io/package/multiformats.md) ^9.4.7
- [s3-streaming-upload](https://npm.io/package/s3-streaming-upload.md) ^0.3.4

## Recent versions

- 0.1.6 (latest) — 2022-12-25

## README

# Filebase Storage JS

seems familiar...
Filebase Storage Js is an SDK to interact with Filebase Storage.

# Methods

## get

The `get` method is for fetching individual files, either the content or related data, such as the key, hash and publicUrl.

Example of usage:

```
const myFile = await filebaseStorage.get({
  apiKey: 'my-key',
  apiSecret: 'my-secret',
  key: 'my-file-key',
  getOptions: [
    'data',
    'bucket',
    'key',
    'hash',
    'publicUrl'
  ],
})
```

### Input parameters of get

|      param | type                                                     | description                                                                                                                                                       |
| ---------: | -------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|     apiKey | String                                                   | The api key used for authentication                                                                                                                               |
|  apiSecret | String                                                   | The api secret used for authentication                                                                                                                            |
|        key | String                                                   | The key identifying the requested file in the bucket                                                                                                              |
|     bucket | String, optional, defaults to the default account bucket | The name of the bucket containing the file. A bucket is created by default with every Filebase account                                                            |
| getOptions | Array, optional, defaults to ['data']                    | An array specifying what type of information to retrieve concerning the file. Possible values for the array includes `data`, `bucket`, `hash`, `key`, `publicUrl` |

## upload

The `upload` method uploads a file, identified by a key, to a bucket.
The function returns the hash of the file, the publicUrl, the key and the bucket.

Example of usage:

```
fs.readFile(filePath, async (error, fileData) => {
  const uploadedFile = await filebaseStorage.upload({
    apiKey: 'my-key',
    apiSecret: 'my-secret',
    key: 'my-file-key',
    data: fileData,
  });
})


```

### Input parameters of upload

|     param | type                                                     | description                                                                                            |
| --------: | -------------------------------------------------------- | ------------------------------------------------------------------------------------------------------ |
|    apiKey | String                                                   | The api key used for authentication                                                                    |
| apiSecret | String                                                   | The api secret used for authentication                                                                 |
|       key | String                                                   | The key identifying the requested file in the bucket                                                   |
|    bucket | String, optional, defaults to the default account bucket | The name of the bucket containing the file. A bucket is created by default with every Filebase account |
|      data | Any                                                      | The data of the file to be uploaded                                                                    |

## deleteFile

The `deleteFile` method deletes a file, identified by its key and bucket.
The function returns the key and bucket of the deleted file if successful.
If the file does not exist, the method will still execute successfully.

Example of usage:

```
  await filebaseStorage.deleteFile({
    apiKey: 'my-key',
    apiSecret: 'my-secret',
    key: 'my-file-key',
    bucket: 'my-bucket',
  });

```

### Input parameters of deleteFile

|     param | type                                                     | description                                                                                            |
| --------: | -------------------------------------------------------- | ------------------------------------------------------------------------------------------------------ |
|    apiKey | String                                                   | The api key used for authentication                                                                    |
| apiSecret | String                                                   | The api secret used for authentication                                                                 |
|       key | String                                                   | The key identifying the file in the bucket                                                             |
|    bucket | String, optional, defaults to the default account bucket | The name of the bucket containing the file. A bucket is created by default with every Filebase account |

## listFiles

The `listFiles` method is for fetching information about all files in a bucket such as the key, hash and publicUrl.

Example of usage:

```
const files = await filebaseStorage.listFiles({
  apiKey: 'my-key',
  apiSecret: 'my-secret',
  prefix: 'my-folder',
  getOptions: [
    'bucket',
    'key',
    'hash',
    'publicUrl'
  ],
})
```

### Input parameters of listFiles

|      param | type                                                        | description                                                                                                                                               |
| ---------: | ----------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- |
|     apiKey | String                                                      | The api key used for authentication                                                                                                                       |
|  apiSecret | String                                                      | The api secret used for authentication                                                                                                                    |
|     bucket | String, optional, defaults to the default account bucket    | The name of the bucket containing the file. A bucket is created by default with every Filebasa account                                                    |
|     prefix | String, optional, defaults to the empty string              | The name of the folder you want to list files in. Can be used to recurse through the folder structure in Filebase Storage                                 |
| getOptions | Array, optional, defaults to ['key', 'bucket', 'publicUrl'] | An array specifying what type of information to retrieve concerning the file. Possible values for the array includes `bucket`, `hash`, `key`, `publicUrl` |

## listBuckets

The `listBuckets` method returns an array of bucket names associated with the api key's account.

Example of usage:

```
const buckets = await filebaseStorage.listBuckets({
  apiKey: 'my-key',
  apiSecret: 'my-secret',
})
```

### Input parameters of listBuckets

|     param | type   | description                            |
| --------: | ------ | -------------------------------------- |
|    apiKey | String | The api key used for authentication    |
| apiSecret | String | The api secret used for authentication |

## getFileFromHash

`getFileFromHash` is a utility function that downloads a file's data from Filebase's IPFS gateway using the hash. The key and secret is not required since the gateway is publicly available.

Example of usage:

```
const myFile = await filebaseStorage.getFileFromHash({
  hash: 'bafybeige4bhzjvrptn7fdz7mqgigzoczcliqpuo7km4jm7vgjg2pbmuhna',
  getFileFromHashOptions: [
    'buffer',
  ],
})
```

### Input parameters of getFileFromHash

|                  param | type                            | description                                                                                                                                                                       |
| ---------------------: | ------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|                   hash | String                          | The hash of the requested file                                                                                                                                                    |
| getFileFromHashOptions | Array, optional, defaults to [] | An array specifying additional options when it comes to fetching by hash. Possible values for the array includes `buffer` (this returns the whole file at once instead of chunks) |

---
_Source: https://npm.io/package/@catalogworks/filebase-storage-js · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
