@filen/sdk
TypeScript icon, indicating that this package has built-in type declarations

0.1.90 • Public • Published

Filen SDK

SDK to interact with Filen for Node.JS, Browsers and React Native.

Explore the docs »

Contributors Forks Stargazers Issues License

Attention

The SDK is still a work in progress. DO NOT USE IT IN PRODUCTION YET. Class names, function names, types, definitions, constants etc. are subject to change until we release a fully tested and stable version.

Installation

  1. Install using NPM
npm install @filen/sdk@latest
  1. Initialize the SDK.
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,
	tmpPath: path.join(os.tmpdir(), "filen-sdk")
})

await filen.login({
	email: "your@email.com",
	password: "supersecret123",
	twoFactorCode: "123456"
})
  1. Interact with the cloud
// 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")
})

License

Distributed under the AGPL-3.0 License. See LICENSE for more information.

Readme

Keywords

Package Sidebar

Install

npm i @filen/sdk

Weekly Downloads

610

Version

0.1.90

License

AGPLv3

Unpacked Size

2.32 MB

Total Files

828

Last publish

Collaborators

  • filen