bamlab / react-native-image-resizer

🗻 Resize local images with React Native
MIT License
1.6k stars 342 forks source link

QUESTION - Resized image file path #311

Closed dittmarconsulting closed 2 years ago

dittmarconsulting commented 2 years ago

Hi all,

First of all, I love this package and I have been using it for quite some time without any issues. Well done 👏

I have a question about the file location of the resized images on iOS. I've had a look at the source code and you use NSFileManager as described here.

Here is my question:

Can the return file path be used as a permanent storage? Meaning, that this file would stay at this position on the file system until it is explicitly deleted by the user or will this file be subject to garbage collection by the OS?

PierreCapo commented 2 years ago

Hello @dittmarconsulting Thanks for your kind words.

This is actually an interesting topic, nice question.

We are currently using NSCachesDirectory by default and NSDocumentDirectory if you use the JS outputPath attribute . From this stack overflow response, it looks like the Caches directory is sometimes clean up by the OS, which makes sense because you can set a size in native to the cache you want. However from this answer it also means that NSDocumentDirectory is not wiped randomly by the OS, which I also believe makes sense because that coud lead our apps to really unstable states if we can not use reliably some external resources in a Document folder.

dittmarconsulting commented 2 years ago

Thanks for the quick reply @PierreCapo.

I want to highlight what I want to do:

I'm planning to save up to 1000 (resized) images, with a total volume of ~150 - 300MB, in the file system of the phone, when the phone is in offline mode. Once the phone is online again, I will sync these images to the cloud and remove them all from the file system automatically. Since I can't predict how long the phone might be offline, I have to make sure these images DO NOT get deleted from the file system by the OS. On the other hand, I don't want to have the resized images in one folder and save the same images in another NSDocumentDirectory folder just to guarantee that the images don't get lost.

That was the background for my question. Because if I could just keep the resized images where they were created by the function createResizedImage it would save me the effort to manage 2 directories.

What do you think?

stale[bot] commented 2 years 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 2 years ago

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