Skip to content
Discussion options

You must be logged in to vote

The correct type depends on which SDK you're using. Here's the full picture:

Admin SDK (Node.js) — use Buffer

import { getFirestore } from 'firebase-admin/firestore';

const db = getFirestore();

// Storing
const buffer = Buffer.from('hello world', 'utf-8');
// From a file: const buffer = fs.readFileSync('./image.png');

await db.collection('files').doc('doc-id').set({
  data: buffer,  // Buffer is accepted directly by the Admin SDK
});

// Retrieving — comes back as Buffer on Node.js
const snap = await db.collection('files').doc('doc-id').get();
const retrieved: Buffer = snap.data()!.data;
console.log(retrieved.toString('utf-8')); // 'hello world'

Web SDK (browser) — use Bytes

import { g…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Vloz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants