Back

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

  • 0
  • Web
Parthsarthi#4947
24 Feb, 2024, 12:38

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.

TL;DR
Error message indicates missing required attribute "image" but code is trying to use "fileUrl" as image. Suggest changing "image" to "imageUrl" in the database structure. Replace "image" with "imageUrl" in the code where the document is created.
D5
24 Feb, 2024, 12:38

What's the code and database structure?

Parthsarthi#4947
24 Feb, 2024, 12:40

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 }

Parthsarthi#4947
24 Feb, 2024, 12:41
D5
24 Feb, 2024, 12:42

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

D5
24 Feb, 2024, 12:43
TypeScript
            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
            }
D5
24 Feb, 2024, 12:45

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

Parthsarthi#4947
24 Feb, 2024, 12:45

after change this is what shown in console

D5
24 Feb, 2024, 12:45

Looks like it's not an URL?

D5
24 Feb, 2024, 12:47

You could try to do console.log and see if it's or not an url here:

TypeScript

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
            }
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