0

Sending small objects from node.js server to Firebase Storage works great. If I have a big object, stringify fails. This is my current code.

const uploadJsonToFirebase = async (jsonObject, firebaseStorage, fullPath) => {
  try {
    const jsonString = JSON.stringify(jsonObject, null, 2);
    const bucket = await firebaseStorage.bucket();
    const file = bucket.file(fullPath);
    const contents = jsonString;

    await file.save(contents);
  } catch (error) {
    console.error("Error uploading JSON to Firebase:", error);
    throw error;
  }
};

module.exports = uploadJsonToFirebase;

And error for big files:

Error uploading JSON to Firebase: RangeError: Invalid string length at JSON.stringify ()

I've tried streaming, but could not figure the right flow. The Objects needs to be stored as .json files, as they will be consumed at a later time by other parts of the aplication.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
  • 1
    It looks like the problem is with your call to JSON.stringify and has nothing to do with Firebase. Before posting to Stack Overflow, it's a good idea to [do a search using the error message](https://overflow.tips/write-good-question/search-and-study) to find out what has already been said about it. – Doug Stevenson Jul 26 '23 at 16:39

0 Answers0