react-native-image-crop-picker icon indicating copy to clipboard operation
react-native-image-crop-picker copied to clipboard

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

Open emclab opened this issue 3 years ago • 1 comments

Version

Tell us which versions you are using:

  • react-native-image-crop-picker v0.37.1
  • react-native v0.66.3

Platform

Tell us to which platform this issue is related

  • Android phone running android 10

Expected behaviour

The image picked up from gallery shall be able to to saved to online storage OSS

Actual behaviour

ENOENT when saving to online storage.

Steps to reproduce

  1. install the app on android phone and try to save image to online storage

Attachments

Here is the code for image picker:

handleAddPicture : (updatePicks, mediaType, cropping=false, croppingData=null) => {  //mediaType 'photo', 'video', or 'any'
    var fileName;
        try {
            var options = {
                mediaType: mediaType,
                cropping:cropping,
                sortOrder:'desc',
                waitAnimationEnd: false,
                //includeBase64:true,
                //includeExif:true,
            };
            if (cropping && mediaType === 'photo') {  //with no corpping, upload single file only
                options.width = croppingData.width;
                options.height = croppingData.height;                
            } else if (!cropping && mediaType === 'photo') {  //with cropping, multiple uploads allowed
                options.multiple = true;                
            } else if (mediaType === 'video') {
                options.multiple = false;    
            };
            //console.log("before openPicker", options);
            ImagePicker
                .openPicker(options)
                .then(response => {
                    const imageAllowedExtensions = ["jpg", "jpeg", "png", "tiff", "tif"];
                    const videoAllowedExtensions = ["mp4" ,"avi", "mts"];
                    //const correspondingMime = ["image/jpeg", "image/jpeg", "image/png"]; 
                    console.log("in helper for picking up image");
                    let extension;
                    response.forEach(function(res, i) {
                        console.log(" image res selected in helper : ", res);
                        //res output example
                        //{"creationDate": "1628315924", "cropRect": null, "data": null, "duration": null, "exif": null, 
                        //"filename" (IOS): "IMG_0009.JPG",  //ONLY for IOS
                        //"height": 408, "localIdentifier": "865991CB-28FA-4ECE-BB33-A52398F6F98E/L0/001", "mime": "image/jpeg", "modificationDate": "1628315924", 
                        //"path": "/Users/macair/Library/Developer/CoreSimulator/Devices/36EFC364-BDC6-45B2-80A4-230396136FA1/data/Containers/Data/Application/B07ADEA0-D2C2-4714-9942-82DE50E34F51/tmp/react-native-image-crop-picker/11EB6007-4138-4E3B-81CB-8E46CE816002.jpg", "size": 40474, 
                        //"sourceURL" (IOS): "file:///Users/macair/Library/Developer/CoreSimulator/Devices/36EFC364-BDC6-45B2-80A4-230396136FA1/data/Media/DCIM/100APPLE/IMG_0009.JPG", "width": 612}
                        
                        if (Platform.OS === 'android') {
                          fileName = res.path.slice(res.path.lastIndexOf('/') + 1);  
                          response[i].fileName = fileName;          //android does not have fileName              
                        } else if (Platform.OS === 'ios') {
                          fileName = res.filename;
                          response[i].fileName = res.filename;  ////in ios the filename is the original file name 
                          //and fileName is the cached file anme by image picker
                        } else {
                          fileName = "";
                          response[i].fileName = "";
                        }
                        console.log("filename in res helper : ", fileName);                        
                        extension = fileName.slice(fileName.lastIndexOf(".") + 1).toLowerCase();
                        console.log(" extension ", extension);
                        if ((mediaType === 'photo' && !imageAllowedExtensions.includes(extension)) || (mediaType === 'video' && !videoAllowedExtensions.includes(extension))) {
                          response.splice(i, 1);  //delete ith image in response when its format not supported
                        };                            
                    });
                    //update state
                    updatePicks(response);
                    return;
                                
                })
                .catch(err => {
                    if (mediaType === 'photo') {
                      console.log("获取照片出错", err);
                    } else if (mediaType === 'video') {
                      console.log("获取视频出错", err);
                    };
                    updatePicks([]);
                    return ;
            });
    
        } catch(err) {
            console.log("打开相册出错", err)
            //updatePicks([]);
            return ;
        };
      },

Here is the filePath of the image: Screenshot_20220126_103702_com xyz_app5

Here is the error thrown when saving to online storage:

Screenshot_20220126_103705_com xyz_app5

// stacktrace or any other useful debug info

Love react-native-image-crop-picker? Please consider supporting our collective: 👉 https://opencollective.com/react-native-image-crop-picker/donate

emclab avatar Jan 27 '22 05:01 emclab

check permission. go the setting in phone > application > find the application in list > check storage permission there.

ghost avatar Apr 28 '22 23:04 ghost