FileSystem API download image not at full size

  1. SDK Version: 35.0.0
  2. Platforms(Android/iOS/web/all): Android

I have a system for downloading an image (using the FileSystem API) from an url and save it to local file (in cache directory).
The problem I have is with big images: normally the image gets downloaded and then i can retrieve the dimensions correctly, but if I have a big image (w: 800px, h: 15040px) then it gets downloaded, but it is smaller than the original size and when i get the dimensions, those are also smaller (w: 100px, h: 1880px).
I’d like to know if there are some limitations with the FileSystem API regarding the size of the files? or am I doing something wrong?

Info: I’m using the managed workflow, if you need anything else I can provide further info.
Thank you.

How are you getting the size and dimensions of the downloaded images? And how exactly are you downloading them? Maybe a snack would be the best way to show what you’re seeing.

To download them I use:

await FileSystem.downloadAsync(url, systemFile);

To get the dimensions I use:

Image.getSize(url, (width, height) => {

FileSystem is from the expo api, while Image.getSize is from react-native

(the whole thing is pretty complex so I don’t know is a snack would be easy to do)

Here’s a snack that demonstrates the problem:

Clearly the file is downloaded correctly, but the Image module is scaling it down for some reason.

Thank you for having created a snack, the problem it’s exactly the one shown in the snack.

I’ve made further tests and if the image is downloaded then moved to the camera roll, the image has the right dimensions, but if you try to load the image even from the gallery, where for sure has the right dimensions, the dimensions retrieved are wrong and the image is smaller.

It now seems to be a problem about images in react-native …?

Yes, it seems so.

A bit of searching turned up some interesting links. e.g., it might be possible to use Image.resolveAssetSource() although that might only work on static images (as opposed to ones you’ve downloaded.)

And there is a React Native issue about this, where the conclusion is basically:

I don’t think this will ever be ‘fixed’ in RN. Fixing it will cause memory issues for many apps, with no benefit outside of your use case which can be solved in other ways.

It seems that there’s no built-in way to get the real dimensions and that the Image module returns dimensions based on how big the image would be when displayed (if I understand correctly.)

So I think your options are:

  1. Create a feature request for a way to get the real dimensions of large images
  2. Eject and write some native code to get the real dimensions that you can use from JavaScript

If you go with the latter option you might want to talk to the Expo team to see if they’ll take a patch to Expo so that in future you can “uneject” your app again.

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