SDK to interact with Filen for Node.JS, Browsers and React Native.
Explore the docs ยป
npm install @filen/sdk@latest
import { FilenSDK } from "@filen/sdk"
import path from "path"
import os from "os"
type FilenSDKConfig = {
email?: string
password?: string
twoFactorCode?: string
masterKeys?: string[]
apiKey?: string
publicKey?: string
privateKey?: string
authVersion?: AuthVersion
baseFolderUUID?: string
userId?: number
metadataCache?: boolean // Cache decrypted metadata in memory. Recommended.
tmpPath?: string // Temporary local path used to store metadata and chunks. Only available in Node.JS.,
connectToSocket?: boolean // Recommended if you are using the virtual FS class. Keeps the internal item tree up to date with remote changes.
}
// You can either directly supply all needed config parameters to the constructor or call the .login() function to fetch them using your login information.
const filen = new FilenSDK({
metadataCache: true,
connectToSocket: true,
tmpPath: path.join(os.tmpdir(), "filen-sdk")
})
await filen.login({
email: "your@email.com",
password: "supersecret123",
twoFactorCode: "123456"
})
// Create a directory
await filen.fs().mkdir({
path: "/Pictures"
})
// Upload a file
await filen.fs().upload({
path: "/Pictures",
source: "/Local/path/to/a/file.jpg"
})
// Read contents of the directory
const content: string[] = await filen.fs().readdir({
path: "/Pictures"
})
// Stat a file
const stats: FSStats = await filen.fs().stat({
path: "/Pictures/file.jpg"
})
// Download a file
await filen.fs().download({
path: "/Pictures/file.jpg",
destination: "/Local/path/to/a/file.jpg"
})
// Read a file
const content: Buffer = await filen.fs().readFile({
path: "/Pictures/file.jpg"
})
// Write to a path
await filen.fs().writeFile({
path: "/text.txt",
content: Buffer.from("foobar", "utf-8")
})
Distributed under the AGPL-3.0 License. See LICENSE for more information.
Generated using TypeDoc