realm-js: [BUG] Using Realm with external storage

Goals

I want to use sdcard on Android to save and load Realm data.

Expected Results

The file can be created and loaded without problems using app’s folder on external storage.

Actual Results

Unfortunately, when running Realm.open, it throws an exception of “Read-only file system”, even after giving runtime permission to read and write external storage. I can see the file was created at the specified path.

screenshot_1524455457

Steps to Reproduce

It’s an old issue that still not fixed. Please also see: #1760 Use below code sample

Code Sample

I open my database like this in react-native:

    componentWillMount() {
        Realm.open({
            schema: [ Constant.BookSchema ],
            path: '/storage/sdcard0/BookDB/db.realm'
        }).then(realm => {
            // some code here
        });
    }

I also add this two line to my AndroidManifest.xml:

    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

It’s create below files in this location /storage/sdcard0/BookDB:

db.realm.managment
    access_control.control.mx
    access_control.write.mx
db.realm
db.realm.lock

But It’s return red error page with Read-only file system error. (something like above image) My device just have internal storage with /storage/sdcard0 location and it’s not have any external SD card. (with Android 5.1.1 OS)

Version of Realm and Tooling

* Realm JS SDK Version: 2.15.3

* Node or React Native: 0.55.4

* Client OS & Version: Android API 25, 27

* Which debugger for React Native: None

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 18 (6 by maintainers)

Most upvoted comments

Fixed in #2235 A release will be made later today

A few observations:

  • Removing Realm completely and just writing something random to the Download folder works fine. Hinting at Realm trying to write something where it shouldn’t.
  • I tried to create a pure Java app with the same behavior of requesting permissions and then creating a Realm in the Download folder. This works fine, which indicates a problem more directly with RealmJS or ReactNative, but since Java and JS instantiate things slightly differently, I’m still investigating that.

@Finneah Thank you very much for this. I can reproduce the error on my end as well. I’m looking into it.