question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Taking a picture with storageOptions.path has no effect

See original GitHub issue

I am trying to take a picture with the camera providing storageOptions like this:

        const options = {
            cameraType: 'back',
            mediaType: 'photo',
            storageOptions: {
                cameraRoll: false, // Don't save photos to the camera roll
                path: "/data/data/com.testapp/itemfiles"
                skipBackup: true, // No need to backup to iClould
            },
        };

        ImagePicker.launchCamera(options, (response) => {
            if (response.didCancel) {
                console.log('User cancelled image picker');
            }
            else if (response.error) {
                console.log('ImagePicker Error: ', response.error);
            }
            else if (response.customButton) {
                console.log('User tapped custom button: ', response.customButton);
            }
            else {
                let source = {uri: response.uri};
            }
        });

Pretty standard stuff, I suppose. The problem I’m having is that the options don’t seem to have any effect The path doesn’t change and the file is saved in the camera roll instead. I have confirmed that the path does exist.

The URI in the response looks like this:

uri: ‘content://com.reportit.provider/app_images/Pictures/image-a3fbe51e-94d8-4564-855c-464ed0d8f0ff.jpg’,

The logs mention this as well:

W/unknown:InspectorPackagerConnection: Couldn’t connect to packager, will silently retry I/TAG: Finished scanning /storage/emulated/0/Pictures/image-5e89bc4d-0f11-4e83-bf37-5283ae39f425.jpg

What am I doing wrong? How can I save pictures to the path I specified?

Additional Information

  • React Native version: 0.48.3
  • Platform: Android (5.0.2 device and 7.0 emulator)
  • Development Operating System: MacOS
  • Dev tools: Android Studio, PhpStorm

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
Selman555commented, Nov 21, 2017

I’ve made a local change to MediaUtils.java:49:

        final File path = ReadableMapUtils.hasAndNotNullReadableMap(options, "storageOptions")
            && ReadableMapUtils.hasAndNotEmptyString(options.getMap("storageOptions"), "path")
            ? new File(reactContext.getExternalFilesDir(Environment.DIRECTORY_DOCUMENTS), options.getMap("storageOptions").getString("path"))
            : (!forceLocal ? Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)
                          : reactContext.getExternalFilesDir(Environment.DIRECTORY_PICTURES));

        // ORIGINAL CODE
        //final File path = ReadableMapUtils.hasAndNotNullReadableMap(options, "storageOptions") && !forceLocal
        //        ? Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)
        //        : reactContext.getExternalFilesDir(Environment.DIRECTORY_PICTURES);

Now I can pass a folder like this:

            storageOptions: {
                cameraRoll: false,
                path: 'itemfiles',
                skipBackup: true, // No need to backup to iCloud
            },

And the path in the response is

“/storage/emulated/0/Android/data/com.app/files/Documents/itemfiles/image-ee46fd5a-e669-4038-a14a-a08df67e0345.jpg”

But cameraRoll: false is still ignored…

0reactions
stale[bot]commented, Jul 21, 2019

Closing this issue after a prolonged period of inactivity. Fell free to reopen this issue, if this still affecting you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Taking a picture with storageOptions.path has no effect #731
I am trying to take a picture with the camera providing storageOptions like this: const options = { cameraType: 'back', mediaType: 'photo', ...
Read more >
react-native-image-picker - persistent storage after rebuild
Here is my function that is called when I add an image. ImagePicker.showImagePicker({ storageOptions: { path: 'myCustomPath', waitUntilSaved: ...
Read more >
10 Tips for Taking Better Smartphone Photos - TIME
Want to take better smartphone photos with your iPhone or Android? Give these suggestions from pro photographers a try.
Read more >
react-native-image-picker - Let's see how to take a photo and ...
Option Required Type iOS Android title X string ○ ○ cancelButtonTitle X string ○ ○ takePhotoButtonTitle X string ○ ○
Read more >
Storage options - Compute Engine - Google Cloud
Snapshots are incremental, and take only minutes to create even if you snapshot disks that are attached to running instances. Restrictions. Regional PD...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found