CameraRoll.saveToCameraRoll is not a function(Expo)

I am trying to store images which are taken using React Native Camera library to Gallery on my Expo project.

When the user presses a button the following function gets triggered:

download = async (imageRef) => {
  try {
    let result  = await takeSnapshotAsync(imageRef, {
      result: "tmpfile",
      width: 1013,
      height: 644,
      quality: 1,
      format: "png",
    });
    await CameraRoll.saveToCameraRoll(result, "photo");
  } catch (e) {
    alert(e);
    console.log('error:', e);
  }
};

takeSnapshotAsync is working properly and able to get valid data-uri.
But The debugger shows the following error on CameraRoll:

TypeError: CameraRoll.saveToCameraRoll is not a function. (In 'CameraRoll.saveToCameraRoll(result, "photo")', 'CameraRoll.saveToCameraRoll' is undefined)

Following is Fullcode.

import { captureRef as takeSnapshotAsync } from 'react-native-view-shot'
import * as CameraRoll from "@react-native-community/cameraroll";

class ViewScreenSnapStore {
  download = async (imageRef) => {
    try {
      let result  = await takeSnapshotAsync(imageRef, {
        result: "tmpfile",
        width: 1013,
        height: 644,
        quality: 1,
        format: "png",
      });
      await CameraRoll.saveToCameraRoll(result, "photo");
    } catch (e) {
      alert(e);
      console.log('error:', e);
    }
  };
}

export default new ViewScreenSnapStore();

Environment:

    "@react-native-community/cameraroll": "^1.3.0",
    "@react-native-community/datetimepicker": "^2.1.0",
    "expo": "~36.0.0",
    "expo-asset": "~8.0.0",
    "expo-font": "~8.0.0",
    "expo-image-picker": "~8.0.1",
    "expo-localization": "~5.0.1",
    "expo-permissions": "~8.0.0",
    "expo-sharing": "~8.0.0",
    "mobx": "5.6.0",
    "mobx-react": "5.3.6",
    "moment": "^2.24.0",
    "native-base": "^2.13.8",
    "react": "~16.9.0",
    "react-dom": "~16.9.0",
    "react-native": "https://github.com/expo/react-native/archive/sdk-36.0.0.tar.gz",
1 Like

Try the following instead:

import CameraRoll from "@react-native-community/cameraroll";

I see the same issue. Can’t resolve it
already use
import CameraRoll from "@react-native-community/cameraroll";
but it still fails

Ah, sorry, if you’re using SDK 36 then you should switch to the MediaLibrary module instead.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.