#file size too large for database.

1 messages · Page 1 of 1 (latest)

violet gorge
#

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?

winter sluice
violet gorge
#

Code that goes with this btw

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.

violet gorge
winter sluice
violet gorge
#

yes its: 9011

#

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

#

so i need to find a way around it

#

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

winter sluice
# violet gorge so i need to find a way around it

Changing the maximum length of an Attribute is not currently supported, so you'll have to delete and recreate the Attribute with a longer max length - you'll probably want to do that before you go into production and have data you don't want to lose

violet gorge
#

Yeah fair enough. What is the max i can set it to though?

#

kinda thought i was pushing it with that length

winter sluice
violet gorge
#

yes

winter sluice
violet gorge
#

gotcha

#

ah its 1,073,741,824

winter sluice
violet gorge
#

Yeah im not sure why it was giving me errors too be honest. Seems to be working fine now. Just cant console.log the object. have to use json stringify

winter sluice
violet gorge
#

yeah

#

well before i stringify.

#

so if i console.log(fileobject)

#

it shows up and same goes with fileToSend

winter sluice
# violet gorge yeah

No other changes to the code whatsover - the only addition is exactly console.log(FileToSend)?

violet gorge
#

yes

#

which now somehow also seems to work???? im getting so confused..

winter sluice
violet gorge
#

Shouldnt be.

winter sluice
#

You mentioned above that it was 9011 characters, but the one you posted here was only 9000

violet gorge
#

still 9011 characters for me

#

My issue is solved now but it does make me wonder why i got this issue in particular..