Back

file size too large for database.

  • 0
  • Self Hosted
  • Databases
xmaniaxz
7 Mar, 2024, 09:54

As said above, Im trying to upload a json string to my database. However i get the following error:

Uncaught (in promise) AppwriteException: Invalid document structure: Attribute "JSONFile" has invalid type. Value must be a valid string and no longer than 9999 chars. Im pretty sure the issue is the filesize in this case. Now my question. What is the best workaround for this?

TL;DR
Developers are encountering an issue with uploading a JSON string to a database due to a file size limitation of 9999 characters. The error "Attribute 'JSONFile' has invalid type..." is displayed. The suggested workaround is to split the JSON data into smaller chunks or consider compressing the data before uploading. Additionally, always check the size limit set for the attribute in the database configuration.
ideclon
7 Mar, 2024, 09:56

What size have you set on the Attribute?

xmaniaxz
7 Mar, 2024, 09:57

Code that goes with this btw

TypeScript
export async function WriteSheetToDatabase(FileToSend) {
  console.log(FileToSend)
  //Make JSON string
  const JsonData = JSON.stringify(FileToSend);
  let SheetID = FileToSend.SheetID;
  const userID = await userId;
  if (!userID) {
    console.error("Could not find active Session!");
    return;
  }
  const fileObject = {
    UserID: userID,
    JSONFile: JsonData,
    SheetID: SheetID,
  };
  //If there is already an existing version, overwrite new saveData
  if (!SheetID) {
    //make document with unique ID.
    const Doc = await database.createDocument(
      process.env.NEXT_PUBLIC_DATABASE_ID,
      process.env.NEXT_PUBLIC_SHEET_COLLECTION_ID,
      ID.unique(),
      fileObject
    );

    fileObject.SheetID = Doc.$id;
    FileToSend.SheetID = fileObject.SheetID;
    fileObject.JSONFile = JSON.stringify(FileToSend);
    console.log("Saved CharacterSheet");

    //Grab doc and grab the $id which is uniqueID. add said ID to to FileToSend.SheetID;
    if (fileObject.SheetID !== null) {
      await database.updateDocument(
        process.env.NEXT_PUBLIC_DATABASE_ID,
        process.env.NEXT_PUBLIC_SHEET_COLLECTION_ID,
        fileObject.SheetID,
        fileObject
      );
    } else {
      console.error("SheetID is null");
    }
  }

also this only happens when i try to console.log() the data out.

xmaniaxz
7 Mar, 2024, 09:57

9999

ideclon
7 Mar, 2024, 09:57

And the string is shorter than that?

xmaniaxz
7 Mar, 2024, 09:58

yes its: 9011

xmaniaxz
7 Mar, 2024, 09:59

though I will go over that 9999 when i update the app further

xmaniaxz
7 Mar, 2024, 09:59

so i need to find a way around it

xmaniaxz
7 Mar, 2024, 09:59

I am self hosting so if anything needs to be changed i can do that

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more