'Image picked from gallery on Android device throws "no such file or directory" when saving to online storage

In my React Native 0.66 app, there is a function saving images to online storage service OSS. Here is the code for saving to OSS:

import AliyunOSS from 'aliyun-oss-react-native';
AliyunOSS.initWithSecurityToken(STSConfig.SecurityToken,STSConfig.AccessKeyId,STSConfig.SecretKeyId,endPoint,configuration); 

const saveOSS = async (bucket_name, objkey, filePath) => {
        return (new Promise((resolve) => {
            AliyunOSS.asyncUpload(bucket_name, objkey, filePath).then( async (res) => {
                resolve(true);
            }).catch(async (error)=>{
                //==<< no such file/directory was thrown. see error image
                setTimeout(()=> {
                    AliyunOSS.asyncUpload(bucket_name, objkey, filePath).then( async (res) => {
                        //console.log("Success : ", res);
                        resolve(true);
                    }).catch(async (error)=>{
                        resolve(false);
                    })
                }, 20);
            })
        }));
    };
...
//<<== filePath returned below is from response out of [image crop picker][1]. 
//It is a cache path. see image below for detail
res = await saveOSS(bucket_name, objkey, filePath);  //<<==

enter image description here

After image was picked (displayed on device), saving it to online OSS throws error in saveOSS on device (One is Android 10. Another device's version not known). Except the image name, the path in error is not exactly the same as the path passed in:

enter image description here

The code above works in dev but not on real android device. How to fix this error of image file not found?

UPDATE: tried 2 image pickers: react-native-image-picker and react-native-image-crop-picker. The error is the same for both on real device. I guess the issue may not be image picker related.

Also here is the permission in AndroidManifest.xml:

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


Solution 1:[1]

  • android device build version?

  • did you app granted the SD card read/write permission?

  • The shareed URL which start with "file://" does not work in Android N?may be? and above?throw security exception.?

  • Could u please check the absolution path in command line? like below:

    adb shell ls -al /path/to/your/image.png

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 caopeng