Back

AppwriteException: Invalid document structure: Missing required attribute "blogImage"

  • 0
  • Web
dantedmc
23 Mar, 2024, 23:58

Sorry for bothering you everyone but I am getting this error

This is my post form relevant part `else { const file = data.image ? appwriteService.uploadFile(data.image[0]) : <Loading />; try { if (file) { const fileId = file.$id data.blogImage = fileId const dbPost = await appwriteService.createPost({ ...data, userId: userData.$id})

TypeScript
        if (dbPost) {
          navigate('/profile')
        }
      }
    } catch (error) {
      console.log(`ERROR POSTING `, error)
    }
  
  }`

This is appwrite services `import {Client, ID, Databases, Storage, Query } from 'appwrite'; import conf from '../conf/conf'

export class AppwriteService{ client = new Client(); databases; storage;

TypeScript
constructor () {
    this.client
        .setEndpoint(conf.appwriteUrl)
        .setProject(conf.appwriteProjectId)
        this.databases = new Databases(this.client);
        this.storage = new Storage(this.client);
}

async createPost ({title, content, blogImage, userId}) {
    try {
        await this.databases.createDocument(
            conf.appwriteDatabaseId,
            conf.appwriteArticleCollectionId,
            userId,
            {
                title,
                content,
                blogImage,
            }
        )
    } catch (error) {
        console.log("Backend :: createPost :: error", error)
        throw error
    }
}`

Please help

TL;DR
Issue: Developer is encountering the error "AppwriteException: Invalid document structure: Missing required attribute 'blogImage'" while trying to post in ReactJs app using Appwrite services. Solution: Ensure the 'blogImage' attribute is being properly set before calling the createPost function in the AppwriteService.
dantedmc
23 Mar, 2024, 23:58

Backend :: createPost :: error AppwriteException: Invalid document structure: Missing required attribute "blogImage" at Client.<anonymous> (http://localhost:5173/node_modules/.vite/deps/appwrite.js?v=de89454e:850:17) at Generator.next (<anonymous>) at fulfilled (http://localhost:5173/node_modules/.vite/deps/appwrite.js?v=de89454e:488:24) PostForm.jsx:52

ERROR POSTING AppwriteException: Invalid document structure: Missing required attribute "blogImage" at Client.<anonymous> (http://localhost:5173/node_modules/.vite/deps/appwrite.js?v=de89454e:850:17) at Generator.next (<anonymous>) at fulfilled (http://localhost:5173/node_modules/.vite/deps/appwrite.js?v=de89454e:488:24)

this is the error

dantedmc
23 Mar, 2024, 23:58

I am using reactJs

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