Friday 28 January 2022

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. 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 to install and use another image picker (react-native-image-picker) and the error is the same on real device. I guess the issue may not be image picker related.



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

No comments:

Post a Comment