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

outputPath does not work correctly on iOS

Open Saikedo opened this issue 3 years ago • 2 comments

When specifying the outputPath, Android works correctly and the output file is placed in the following folder for example (exactly what was provided to the library).

data/user/0/net.eksperience.myapp/cache/MB_ImageCompressor/c4e80d26-8055-4c1b-84ed-d47ab9b2aa3a.WEBP

However, on iOS, when I provide an outputPath of

/var/mobile/Containers/Data/Application/C5B63F2E-6A2C-4A1F-8745-8F23445FDE50/Library/Caches/MB_ImageCompressor

the file is not stored in the correct location. It seems like the provided outputPath just gets appended to whenever it was going to store the file. The result is this

'/var/mobile/Containers/Data/Application/C5B63F2E-6A2C-4A1F-8745-8F23445FDE50/Documents/var/mobile/Containers/Data/Application/C5B63F2E-6A2C-4A1F-8745-8F23445FDE50/Library/Caches/MB_ImageCompressor/0BAABF92-984C-48A6-BC72-2594851E07D6.jpg'

I also tried to just provide the folder name, and that does not work either because instead of storing it in Caches/folderName, it stores it in Documents.

Any idea what might be going wrong here ?

Saikedo avatar Aug 27 '22 14:08 Saikedo

Hi @Saikedo,

On which version are you experiencing the issue ? Can you provide me an example ?

If you want to investigation deeper on your side I think you should look into ios/ImageResizer.mm in generateFilePathmethod.

taboulot avatar Aug 29 '22 08:08 taboulot

Hi @taboulot

I just actually realized that this is the one that I was using and it seems like that one is deprecated https://www.npmjs.com/package/react-native-image-resizer. It was using 1.4.5.

Will try with the new one and will keep you posted if the same issue is occurring there as well.

Saikedo avatar Aug 29 '22 18:08 Saikedo

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 Oct 28 '22 18:10 stale[bot]

I am having this issue and I am using 3.0.4. Were you able to figure this out?

codeundercoverdev avatar Nov 01 '22 18:11 codeundercoverdev

Has anyone fixed this out? We are unfortunately abandoning the library if we can't fix this.

codeundercoverdev avatar Dec 22 '22 01:12 codeundercoverdev

@Saikedo & @codeundercoverdev

Finally, I had time to look deeper.

The related code is here : https://github.com/bamlab/react-native-image-resizer/blob/254e4df2aa2889d223af84006d3a06ce9864a8f1/ios/ImageResizer.mm#L133-L139

The problem (it looks like it was already the case before) is that :

  1. The image is saved inside the Cache directory if no outputPath has been provided;
  2. If outputPath is a subdirectory of Documents, it is created there ;
  3. Else, the provided outputPath is added to Documents path (it explains what you have @Saikedo );

Two solutions here :

  1. Do not save in Cache directory, use Documents instead;
  2. Contributions are welcome to improve this part :)

I hope it helped.

taboulot avatar Feb 13 '23 14:02 taboulot

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 Apr 14 '23 15:04 stale[bot]

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

stale[bot] avatar Apr 21 '23 16:04 stale[bot]