logo
Storage SDKRead Operations

Reading files from bucket

Perform Read Operations

This doc covers:

  • Listing files in a bucket
  • Getting a public URL for a file
  • Reading/downloading a file

List bucket files

import { getInstance } from 'nvsfsdk';

const ns = getInstance();

// No bucket name needed anymore!
const { objects } = await ns.listFiles();
for (const o of objects) {
  console.log(o.key, o.size);
}

Get a file URL

This constructs the path-style URL using the storage node endpoint. The bucket name is automatically resolved from your token.

const url = await ns.getFileUrl('uploads/file.png');
console.log(url);

Read a file

The SDK returns URLs; you can fetch them with fetch / axios.

import axios from 'axios';

const url = await ns.getFileUrl('hello.txt');
const res = await axios.get(url, { responseType: 'arraybuffer' });
console.log(Buffer.from(res.data));

Read using pre-signed URL

If your bucket is private and you want a temporary unauthenticated URL:

const signed = await ns.presignUrl('hello.txt', { ttl: 60, method: 'GET' });
const res = await fetch(signed.signedUrl);
console.log(await res.text());