Files/folders

Once you have a vault in Tusky, you can structure your data into files and folders.

Upload fileCopied!

From pathCopied!

const path = "/path/to/my/file.jpg";
const uploadId = await tusky.file.upload(vaultId, path);

From streamCopied!

import { createReadStream } from "fs";
const fileStream = createReadStream("/path/to/my/file.jpg");

const uploadId  = await tusky.file.upload(vaultId, fileStream, { name: "file.jpg", mimeType: "image/jpeg" });

From bufferCopied!

const uploadId = await tusky.file.upload(vaultId, new Blob(["hello world"]), {
    name: "hello_world.txt",
    mimeType: "text/plain",
});

Get file metadataCopied!

The field uploadId returned during file.upload() call is the internal Tusky file identifier populated immediately during upload, while blobId and blobObjectId are computed in an asynchronous manner while encoding & uploading the file to Walrus, hence these fields may take some time to be populated.

See the detailed file fields description here.

const fileMetadata = await tusky.file.get(uploadId);

// blobId - file reference off chain
// computed deterministically from blob content
console.log("File Walrus blob id: " + fileMetadata.blobId);

// blobObjectId - file reference on chain
console.log("File Sui object id: " + fileMetadata.blobObjectId);

Download fileCopied!

BufferCopied!

method file.arrayBuffer() will put whole file in memory, for larger files we recommend using file.stream() or file.download()

const fileBuffer = await tusky.file.arrayBuffer(fileId);

StreamCopied!

Stream file

const fileStream = await tusky.file.stream(fileId);

Stream file & save it in provided path in your local file system

await tusky.file.download(fileId, { path: "path/to/save/your/file" });

Create folderCopied!

const { id: folderId } = await tusky.folder.create(vaultId, "your folder name");

Now you can upload your next file into the newly created folder

const uploadId = await tusky.file.upload(vaultId, fileBuffer, { parentId: folderId });

List filesCopied!

List all user filesCopied!

const files = await tusky.file.listAll();

List all files within the vaultCopied!

const files = await tusky.file.listAll({ vaultId: vaultId });

List all files within the folderCopied!

const files = await tusky.file.listAll({ parentId: folderId });