`uri `is null when using FileSystem.getInfoAsync on an emulator image.

Please provide the following:

  1. SDK Version: 40.0.1
  2. Platforms(Android/iOS/web/all): iOS (emulator)
  3. Add the appropriate “Tag” based on what Expo library you have a question on.

When using FileSystem.getInfoAsync with an emultator asset URI “assets-library://asset/asset.JPG?id=99D53A1F-FEEF-40E1-8BB3-7DD55A43C8B7&ext=JPG” I get a return value where the uri is null

Is there a way of preventing that as it is impacting testing.

Hey @trajano, does this occur with every asset you’ve tried? Also, can you let me know what OS version you are running on the simulator?

Cheers,
Adam

Only with the ones built into the emulator. Though that’s the only ones I have used so far. I have created a workaround for this though. The approach was to copy the file the cache but try to preserve the extension. I move it after my upload process so I don’t have the code to delete the file in the snippet below.

  /**
   * @typedef {Object} ParamArtifact
   * @property {string} uri uri
   */
  /**
   * @typedef {Object} FormData
   * @property {ParamArtifact[]} artifacts artifacts
   * @property {string} id form ID
   */

        const copyOperationObjects = values.artifacts
          .map((artifact) => {
            return {
              url: new URL(artifact.uri),
              parsed: new Url(artifact.uri),
            };
          })
          .map(({ url, parsed }, index) => {
            return {
              artifactUri: url.toString(),
              destinationUri: `${
                FileSystem.cacheDirectory
              }copy${Date.now()}-${index}${parsed.pathname.substring(
                parsed.pathname.lastIndexOf('.')
              )}`,
            };
          });
        const localCopyUris = await Promise.all(
          copyOperationObjects.map(async ({ artifactUri, destinationUri }) => {
            await FileSystem.copyAsync({
              from: artifactUri,
              to: destinationUri,
            });
            return destinationUri;
          })
        );
        const fileInfos = await Promise.all(
          localCopyUris.map((localCopyUri) =>
            FileSystem.getInfoAsync(localCopyUri, { md5: true, size: true })
          )
        );

In my patch, I needed to ensure that the extension is kept, but React Native does not natively support URL.pathname so I used a 3rd party library to do the work though the 3rd party library also had an issue in that it didn’t support file:/// (it reduces it to file://) so far this is working, I’ll check if there’s a better approach without me having do maintain as much code.

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