Realm returns empty data field
See original GitHub issueHi there,
Goals I try am trying to save an image to realm and then read it.
Expected results The database query should return the ArrayBuffer which represents the data of the image.
Actual results
Saving the ArrayBuffer seems to work as realm.create
returns a valid object. When trying to read the image from the database, it only returns the id field, but the image data is empty.
Steps to reproduce Save an ArrayBuffer and then read it.
Code
import Realm from 'realm';
import { encode, decode } from 'base64-arraybuffer';
const PlantSchema = {
name: 'Plant',
properties: {
id: 'int',
image: 'data'
}
};
let realm = new Realm({schema: [PlantSchema]});
class Plant {
getPlantImage(id) {
const plants = realm.objects('Plant').filtered(`id == ${id}`);
console.log(plants[0].image); // { '0': { id: 12, image: {} } }
...
}
save(id, imageData) {
const decoded = decode(imageData); //base64 to ArrayBuffer
realm.write(() => {
let plant = realm.create('Plant', {
id: id,
image: decoded
});
console.log('saved: ' + plant.image); // prints saved: [object ArrayBuffer]
});
}
}
Versions
- Realm: 0.15.0
- react-native: 0.38.0
- react: 15.4.1
- Xcode: 8.1
- iPhone 6 Simulator
- OSX: 10.12.1
Thanks a lot Tobias
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Realm.objects(Type) return empty objects - Stack Overflow
the data is already in the database , I can see the data in Realm browser but when I try to get it...
Read more >MongolDB Realm is returning an empty realm
Hello everyone, Lately I've been looking into using SwiftUI to implement my app, I used the guidelines from this repository: ...
Read more >Realm Database on Android: Getting Started
Learn how to use Realm database on Android for data persistence. You'll learn how to add it to your android app and utilize...
Read more >RealmResults (Realm 1.1.0)
Returns an Rx Observable that monitors changes to this RealmResults. double, average(java.lang.String fieldName). Returns the average of a given field.
Read more >2272271 - No Realm is available - Unable to select any Object ...
When creating an Advanced Reporting query, the drop down shows 'No Realm is ... No Realm is available - Unable to select any...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
So do data fields just not work in Realm JS at all? The issue is still present on 2.3, and it looks like this bug has been open for over a year.
Update: There doesn’t seem to be any issues with the Node version, just React Native.
Update 2: The issue seems to be related to the fact that
Buffer
is not present in React Native. In order to get access to data fields and work around this issue, you can do this:npm install buffer
(or Yarn)import { Buffer } from 'buffer'
Buffer.from()
on your data field. Using the original post, you’d call:realmData
will contain your previously saved image data (or whatever binary you stored.) If you need it in ArrayBuffer format, you can just userealmData.buffer
which will be aUint8Array
.Hope this helps!
I’m also having the same issue.