react-native-image-resizer icon indicating copy to clipboard operation
react-native-image-resizer copied to clipboard

Unable to load source image from path

Open m191007 opened this issue 8 years ago • 11 comments

on android platfrom Unable to load source image from path

m191007 avatar Jun 15 '17 05:06 m191007

I got this issue too.

daominhsangvn avatar Aug 03 '17 06:08 daominhsangvn

Can you post the full stackstrace of the error? Can you also console.log the path of the image?

4ian avatar Aug 03 '17 09:08 4ian

I have fixed this, i got this error because i pass the file path which is lead to nothing.

daominhsangvn avatar Aug 03 '17 11:08 daominhsangvn

Same problem. But i am sure that i passed the current image uri to the createResizedImage(...)

tikkichan4 avatar Sep 22 '17 03:09 tikkichan4

same problem, works in ios and not works in android

RagamAnekaGlobal avatar Oct 22 '17 11:10 RagamAnekaGlobal

same issue. Image is present. Other images in same path have been uploaded but not this particular image. RNFS.readFile(ap[1], 'base64') this code successfully reads the file but createResizedImage is not able to

Even passing in base 64 format does not help "data:image/jpeg;base64,"+imageBase64

zahid313 avatar Nov 03 '17 15:11 zahid313

For the android, you must use base64 then use RNFS to create new image based on the base64.

daominhsangvn avatar Nov 06 '17 04:11 daominhsangvn

Try this:

response = async (result) => {
   let path = result.uri || result.path;
      if (Platform.OS === 'android') {
        let newFilePath = `${RNFetchBlob.fs.dirs.CacheDir}/${path.substring(path.lastIndexOf('/') + 1)}`;
        let newFile = await RNFetchBlob.fs.writeFile(`${RNFetchBlob.fs.dirs.CacheDir}/${path.substring(path.lastIndexOf('/') + 1)}`,
          result.base64,
          'base64');
        path = newFilePath;
      }

      if (/^\/private/.test(path)) {
        path = path.substring(8);
      }
      if (!/^file:/.test(path)) {
        path = `file://${path}`;
      }

      return {
        height: result.height,
        width: result.width,
        isVertical: true,
        cancelled: false,
        uri: path,
        fileSize: result.size,
        mime: result.mime,
        data: result.data
      };
  };

  action = async (type) => {
    let result;
    let options = {
      cropping: true,
      allowsEditing: true,
      aspect: [1, 1],
      base64: Platform.OS === 'android'
    };

    switch (type) {
      case 1:
        result = await ImagePicker.openCamera(options);
        break;
      case 2:
        result = await ImagePicker.openPicker(options);
        break;
    }

    if (result && !result.cancelled) {
      return await this.response(result);
    }
    return null;
  };

daominhsangvn avatar Nov 07 '17 02:11 daominhsangvn

Getting the same error in android: Unable to load source image from path Any update on this? @PierreCapo @robertbarclay @JimTeva

Gopalakrishnan-V avatar Dec 05 '20 06:12 Gopalakrishnan-V

It could be a scoped storage issue. I solved it by adding:android:requestLegacyExternalStorage="true" to my AndroidManifest, inside the application tag. Note that this is a temporary workaround and may not work for Android 11 (API level 30) and beyond.

apgsn avatar Jan 13 '21 09:01 apgsn

This error also could be thrown if data schema is not compatible with android impl. In my case I had to fix "Unable to load source image from path" Android while iOS was working perfectly. The cause was misspelling: data:image/jpg;base64,${base64Image} was used instead of data:image/jpeg;base64,${base64Image} (note jpg vs jpeg). Plugin's native android part requires strict scheme while iOS not.

mikekudzin avatar Apr 26 '21 21:04 mikekudzin

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Sep 01 '22 18:09 stale[bot]

This issue has been automatically closed. Thank you for your contributions.

stale[bot] avatar Sep 08 '22 18:09 stale[bot]