Skip to main content

Download File

Download the full file as binary data using client.storage.downloadFile(). The result includes the file contents in bytes.

Function Signature

client.storage.downloadFile(params: DownloadFileParams): Promise<DownloadFileData | BolticErrorResponse>

Parameters

DownloadFileParams

FieldTypeRequiredDescription
file_namestringFull object path (same as list fullPath)
sizeBytesnumber or stringSize in bytes; if omitted, the client resolves size when needed
storageTypestringOptional storage type

Return Value

DownloadFileData

FieldTypeDescription
bytesArrayBufferFile contents
statusnumberOptional status metadata
contentTypestringOptional MIME type hint

Example

import { createClient, isErrorResponse } from "@boltic/sdk";
import { writeFileSync } from "fs";

const client = createClient("your-api-key");

const result = await client.storage.downloadFile({
file_name: "my-app/exports/data.csv",
});

if (isErrorResponse(result)) {
console.error(result.error.message);
} else {
writeFileSync("./data.csv", Buffer.from(result.bytes));
console.log("Saved", result.contentType, result.status);
}

With known size

const result = await client.storage.downloadFile({
file_name: "my-app/exports/data.csv",
sizeBytes: 1024,
});

Pass sizeBytes from a previous list() row’s size when you already have it so the download does not need to look up the size again.

Error handling

Treat isErrorResponse(result) before reading result.bytes.

  • Overview — Full path rules
  • List — Obtain fullPath and size