Hi!
I’m using the WildAid O-FISH post to create a similar project using 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: "Trait{}?",
errors: "{}?",
score: "Score?",
},
};
export const TraitSchema = {
name: "Trait",
embedded: true,
properties: {
value: "float?",
unit: "string",
},
};
export const ScoreSchema = {
name: "Score",
embedded: true,
properties: {
score: "int",
total: "int",
minusPoints: { type: "MinusPoint[]", default: [] },
},
};
export const MinusPointSchema = {
name: "MinusPoint",
embedded: true,
properties: {
value: "int",
reason: "string",
},
};
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!