Realm JS + React-Native: “no internal field” when creating a new object

325 views Asked by At

I’m using the WildAid O-FISH post to create a similar project using realm JS react-native SDK with flexible sync.

I’m trying to create a Photo object but I get a “no internal field” error.

Here’s my Photo model

export class Photo extends Realm.Object {
    _id;
    user;
    result;
    picture;
    pictureUrl;
    annotation;
    userInputs;
    createdAt;
    projectId;

    static schema = {
        name: "Photo",
        properties: {
            _id: "objectId",
            user: "string",
            result: "Result?",
            picture: "data?",
            pictureUrl: "string?",
            annotation: "string?",
            userInputs: "{}?",
            createdAt: "date",
            projectId: "objectId",
        },
        primaryKey: "_id",
    };
}

export const ResultSchema = {
    name: "Result",
    embedded: true,
    properties: {
        traits: "{}?",
        errors: "{}?",
        score: "{}?",
    },
};

And here’s how I’m creating a new photo

// Write transaction omitted
// Read a local image and convert it to base64
const picture = await readFile(path, "base64");
// Convert the base64 image to Buffer
const binaryBuffer = Buffer.from(picture, "base64");

const newPhoto = realm.create("Photo", {
    _id: new Realm.BSON.ObjectId(),
    user: user.profile.email,
    userInputs: section.userInputs,
    createdAt: new Date(),
    projectId: new Realm.BSON.ObjectId(projectId),
    annotation: "someString",
    picture: binaryBuffer,
})

I feel like the problem might come from the picture property. I read in the doc that data type maps to ArrayBuffer which is what a Buffer is. Maybe it’s another field causing the problem but I really don’t know which one.

Thanks in advance!

0

There are 0 answers