Getting this Error-AppwriteException: Invalid document structure: Missing required attribute "image"
- 0
- Web

When i am trying to create post i get this error. My image is being uploaded to storage in Appwrite but my post is not being created. please help asap.

What's the code and database structure?

it is showing error for this code area-const newPost = await databases.createDocument( appwriteConfig.databaseId, appwriteConfig.postCollectionId, ID.unique(), { creator: post.userId, caption: post.caption, imageUrl: fileUrl, imageId:uploadedFile.$id, location: post.location, tags: tags }


You have an attribute who is image instead of imageUrl and you're not specifying it. So that should be the solution:

appwriteConfig.databaseId,
appwriteConfig.postCollectionId,
ID.unique(),
{
creator: post.userId,
caption: post.caption,
image: fileUrl, //This is what changed
imageId:uploadedFile.$id,
location: post.location,
tags: tags
}

Also, a small suggestion: i'ts not needed to save the entire image url if you have the fileID since you can recreate the URL by having the image ID

after change this is what shown in console

Looks like it's not an URL?

You could try to do console.log and see if it's or not an url here:
console.log(fileUrl);
appwriteConfig.databaseId,
appwriteConfig.postCollectionId,
ID.unique(),
{
creator: post.userId,
caption: post.caption,
image: fileUrl, //This is what changed
imageId:uploadedFile.$id,
location: post.location,
tags: tags
}
Recommended threads
- Subdomain failed verification
So I wanted to do a custom subdomain, because local storage doesn't work for me, but I've tried it a long time ago, it didn't work for me, and now I'm trying ag...
- [Node.js SDK] Bypass 2GB file limit?
Hello. Using either InputFile.fromPath or InputFile.fromBuffer throws this error: File size (2295467305) is greater than 2 GiB Bucket limit etc. is setup corre...
- Relationship null, even when relationshi...
Hi Everyone, im experiencing issues with set relation data. When im setting the document id from the related database most of them seem fine, except one table. ...
