https://github.com/omnipin/filebase-upload
💾 Minimal library to upload files on Filebase S3 API. Partially based on AWS SDK v3.
https://github.com/omnipin/filebase-upload
filebase ipfs s3
Last synced: 7 days ago
JSON representation
💾 Minimal library to upload files on Filebase S3 API. Partially based on AWS SDK v3.
- Host: GitHub
- URL: https://github.com/omnipin/filebase-upload
- Owner: omnipin
- License: apache-2.0
- Created: 2023-11-23T21:19:36.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2025-12-30T01:45:57.000Z (22 days ago)
- Last Synced: 2026-01-02T09:59:14.814Z (18 days ago)
- Topics: filebase, ipfs, s3
- Language: TypeScript
- Homepage: https://npm.im/@stauro/filebase-upload
- Size: 139 KB
- Stars: 3
- Watchers: 0
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# filebase-upload
[![Version][v-badge-url]][npm-url] [![GitHub Workflow Status][gh-actions-img]][github-actions]
[![Codecov][cov-badge]][cov] [![][docs-badge]][docs]
Minimal library to upload files on [Filebase](https://filebase.com) S3 API. Partially based on
[AWS SDK v3](https://github.com/aws/aws-sdk-js-v3).
## Install
For Node.js:
```sh
pnpm i @omnipin/filebase-upload
```
For Deno:
```sh
deno add jsr:@omnipin/filebase-upload
```
## Usage
First, you need to set up a token. A token is a base64 encoded pair of the access key and access secret.
You can generate a token like this:
```sh
echo "accessKey:accessSecret" | base64
```
and save it to a `.env` file or somewhere else.
The default `apiUrl` is `s3.filebase.com`. To change, pass in the url to the `apiUrl` arg.
### Node.js
```ts
import { createPresignedUrl } from '@omnipin/filebase-upload'
const file = new File(['Hello world'], 'hello.txt')
const url = await createPresignedUrl({
bucketName: `example-${crypto.randomUUID()}`,
token: process.env.FILEBASE_TOKEN,
file,
})
await fetch(decodeURIComponent(url), { method: 'PUT', body: file })
```
And then run as:
```sh
node --env-file=.env main.js
```
### Deno
```ts
import { createPresignedUrl } from '@omnipin/filebase-upload'
import { load } from '@std/dotenv'
const env = await load()
const file = new File(['Hello world'], 'hello.txt')
const url = await createPresignedUrl({
bucketName: `example-${crypto.randomUUID()}`,
token: env.FILEBASE_TOKEN,
file,
})
await fetch(decodeURIComponent(url), { method: 'PUT', body: file })
```
And then run as:
```sh
deno --allow-read --allow-net mod.ts
```
## API
### uploadCar
Upload a CAR file using `createPresignedUrl`. Returns a response object.
```ts
import { uploadCar } from './mod.ts'
import { load } from 'https://deno.land/std@0.207.0/dotenv/mod.ts'
import { CAREncoderStream, createFileEncoderStream } from 'https://esm.sh/ipfs-car@1.0.0'
import { CID } from 'https://esm.sh/multiformats@12.1.3/cid'
const env = await load()
const init = {
bucketName: `filebase-upload-tests`,
token: env.FILEBASE_TOKEN,
}
const placeholderCID = CID.parse('bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi')
const stream = createFileEncoderStream(new Blob(['Hello ipfs-car!']))
.pipeThrough(
new TransformStream(),
)
.pipeThrough(new CAREncoderStream([placeholderCID]))
const blob = await new Response(stream).blob()
const file = new File([blob], 'file.car')
const res = await uploadCar({ ...init, file })
console.log(res.headers.get('x-amz-meta-cid'))
```
### createPresignedUrl
Creates a presigned URL for file upload. All options except apiUrl and `metadata` are required.
Passing a `metadata` object converts to a header object with `x-amz-meta-`.
### getObject
Retrieves an object from Filebase S3 API and returns a response object.
You can also retrieve the file CID from headers.
```ts
import { getObject } from 'https://deno.land/x/filebase_upload/mod.ts'
const res = await getObject({
bucketName: `example-${crypto.randomUUID()}`,
token: env.FILEBASE_TOKEN,
filename: 'hello.txt',
})
console.log(`${res.headers.get('x-amz-meta-cid')}:`, await res.text())
```
### headObject
Checks if the file has been uploaded. Returns a boolean and a CID of the file (if uploaded).
```ts
import { headObject } from 'https://deno.land/x/filebase_upload/mod.ts'
const [isUploaded, cid] = await headObject({
bucketName: `example-${crypto.randomUUID()}`,
token: env.FILEBASE_TOKEN,
filename: 'hello.txt',
})
console.log(`is uploaded? ${isUploaded ? 'yes' : 'no'}`)
```
[docs-badge]: https://img.shields.io/github/v/release/staurodev/filebase-upload?label=Docs&logo=deno&style=for-the-badge&color=FFAE00
[docs]: https://doc.deno.land/https/deno.land/x/filebase_upload/mod.ts
[gh-actions-img]: https://img.shields.io/github/actions/workflow/status/staurodev/filebase-upload/ci.yml?branch=master&style=for-the-badge&logo=github&label=&color=FFAE00&
[github-actions]: https://github.com/staurodev/filebase-upload/actions
[cov]: https://coveralls.io/github/StauroDEV/filebase-upload
[cov-badge]: https://img.shields.io/coveralls/github/StauroDEV/filebase-upload?style=for-the-badge&color=FFAE00
[v-badge-url]: https://img.shields.io/npm/v/@omnipin/filebase-upload?style=for-the-badge&logo=npm&label=&color=FFAE00
[npm-url]: https://www.npmjs.com/package/@omnipin/filebase-upload