0.0.4
💾 Minimal library to upload files on Filebase S3 API. Partially based on AWS SDK v3.
Attributes
Includes Deno configuration
Repository
Current version released
2 years ago
Dependencies
filebase-upload
Minimal library to upload files on Filebase S3 API. Partially based on AWS SDK v3.
Install
pnpm i @stauro/filebase-uploadUsage
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:
echo "accessKey:accessSecret" | base64and save it to a .env file or somewhere else.
Node.js
import { createPresignedUrl } from '@stauro/filebase-upload'
const file = new File(['Hello world'], 'hello.txt')
const url = await createPresignedUrl({
bucketName: `example-${crypto.randomUUID()}`,
token: process.env.FILEBASE_TOKEN,
file,
apiUrl: 's3.filebase.com',
})
await fetch(decodeURIComponent(url), { method: 'PUT', body: file })And then run as:
node --env-file=.env main.jsDeno
import { createPresignedUrl } from 'https://deno.land/x/filebase_upload/mod.ts'
import { load } from 'https://deno.land/std@0.207.0/dotenv/mod.ts'
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,
apiUrl: 's3.filebase.com',
})
await fetch(decodeURIComponent(url), { method: 'PUT', body: file })And then run as:
deno --allow-read --allow-net mod.tsAPI
createPresignedUrl
Creates a presigned URL for file upload. All options are required.
getObject
Retrieves an object from Filebase S3 API and returns a response object.
You can also retrieve the file CID from headers.
import { getObject } from 'https://deno.land/x/filebase_upload/mod.ts'
const res = await getObject({
bucketName: `example-${crypto.randomUUID()}`,
token: env.FILEBASE_TOKEN,
apiUrl: 's3.filebase.com',
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).
import { headObject } from 'https://deno.land/x/filebase_upload/mod.ts'
const [isUploaded, cid] = await headObject({
bucketName: `example-${crypto.randomUUID()}`,
token: env.FILEBASE_TOKEN,
apiUrl: 's3.filebase.com',
filename: 'hello.txt',
})
console.log(`is uploaded? ${isUploaded ? 'yes' : 'no'}`)