After updating App, URI under FileSystem.documentDirectory no longer works

Hello Forums, I would appreciate if anyone could give me some advice on the following issues. (I’m not good at English, so I’m sorry if it is difficult for you to understand my English.)

I use image picker to pick an image and store the image URI to FileSystem.documentDirectory With the following code.

  onAddImagePressed = async () => {
    const { status } = await Permissions.askAsync(Permissions.CAMERA_ROLL);
    if (status === 'granted') {
      const result = await ImagePicker.launchImageLibraryAsync({
        allowsEditing: true,
        mediaTypes: ImagePicker.MediaTypeOptions.Images,
      });
      if (!result.cancelled) {
        const dirPath = await FileSystem.getInfoAsync(
          `${FileSystem.documentDirectory}ImagesDir`,
        );

        if (!dirPath.isDirectory) {
          try {
            await FileSystem.makeDirectoryAsync(
              `${FileSystem.documentDirectory}ImagesDir`,
              { intermediates: true },
            );
          } catch (e) {
            console.log(e);
          }
        }
        const imageID = this.state.articleIndex;
        const imagePath = await `${
          FileSystem.documentDirectory
        }ImagesDir/${imageID}.jpg`;

        await FileSystem.copyAsync({
          from: result.uri,
          to: imagePath,
        });
        this.setState({
          articleImg: imagePath,
        });
      }
    }
  };

I can save successfully with the above source code.
But, when I update the app in appstore, appID changes every time as below and the URI no longer works.

  • before update -
    "file:///var/mobile/Containers/Data/Application/7E1D8266-17C7-4777-A0DD-CDC1D5AC334F/Documents/ExponentExperienceData/…

  • after update -
    "file:///var/mobile/Containers/Data/Application/1CA13561-A6C4-4780-9E66-31A02719EE4F/Documents/ExponentExperienceData/…

How to manage this problem?
Thank you in advance for your help.


*ExpoSDK version: “32.0.0”
*Referenced question

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.