bamlab / react-native-image-resizer

🗻 Resize local images with React Native
MIT License
1.61k stars 347 forks source link

outputPath does not work correctly on iOS #318

Closed Saikedo closed 1 year ago

Saikedo commented 2 years ago

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 ?

taboulot commented 2 years ago

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.

Saikedo commented 2 years ago

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.

stale[bot] commented 1 year ago

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.

codeundercoverdev commented 1 year ago

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

codeundercoverdev commented 1 year ago

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

taboulot commented 1 year ago

@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.

stale[bot] commented 1 year ago

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] commented 1 year ago

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