0

I am using react-native-photos-framework for creating user defined album and creating assets into device native gallery.

In my app I gives an user defined album creation functionality to user. For that I am displaying a simple modal with input field where user can type album name and 'OK' and 'CANCLE' button.

What I want ?
I want that when user click on 'OK' button after typing album name in input field, a typed album should be created in gallery and one by default image (which is in my local directory) should added to that album.

Here is the code that i used :

createAlbum() {
    RNPhotosFramework.createAlbum(this.state.createAlbumName).then((album) => {
      RCTCameraRollRNPhotosFrameworkManager.createAssets({
        images : [{ uri : '../assets/logo.png' }],
        album : album,
        includeMetadata : true 
      });
    }).catch((error)=>{
      alert("Error in creating album : \n"+JSON.stringify(error));
    });
}

As you can see, I am first creating album which is creating successfully in gallery, But assets is not copying in that album. It is giving me this error :

Could not find image file:///Users/vision/Library/Developer/CoreSimulator/Devices/E5AA1780-A55C-4C67-95A5-222E4AS3PA23/data/Containers/Bundle/Application/5E37FAF5-15DD-483B-3BD6-C311C587SD8/CameraApp.app/../assets/imgs/logo.png

I have also used require() to get image uri as follow :

images : [{ uri : require('../assets/logo.png' )}],

but then app will crash.

Here is the my project structure :

my project directory structure.

Please help me how I can create asset of local static image using react-native-photos-framework. I am new to react native !!!

Kishan Bharda
  • 5,446
  • 3
  • 30
  • 57

1 Answers1

0

If anyone also running in this problem I have solved problem using this answer.

To solve the problem first install react-native-fs.

Then import it in your project.

const RNFS = require('react-native-fs');

Then I used RNFS.MainBundlePath to get my app root path and add assets before my actual path.

Here is code :

createAlbum() {
    RNPhotosFramework.createAlbum(this.state.createAlbumName).then((album) => {
      RCTCameraRollRNPhotosFrameworkManager.createAssets({
        images : [{uri:RNFS.MainBundlePath+'assets/src/assets/imgs/logo.png'}],
        album : album,
        includeMetadata : true
      }).then((result)=>{
        alert(JSON.stringify(result));
      }).catch((error)=>{
        alert("Error in creating assets.\n"+JSON.stringify(error));
      });
    });
}

Hope it will help someone.

Community
  • 1
  • 1
Kishan Bharda
  • 5,446
  • 3
  • 30
  • 57