Hi,
I’m looking into ways to preserve an avatar picture taken with ImagePicker.
using AsyncStorage seems to be a no go since there’s size limitation.
So I’m trying to figure out how to use FileSystem.
What I understand is that:
- After I get the base64 encoded image from ImagePicker, I need to make a directory to store it by using
Expo.FileSystem.makeDirectoryAsync(Expo.FileSystem.cacheDirectory+'/avatar')
- Then I have to save the image using
Expo.FileSystem.writeAsStringAsync(Expo.FileSystem.cacheDirectory+'/avatar', 'data:image/jpg;base64,'+base64Image)
- Retrieve it by using
Expo.FileSystem.readAsStringAsync(Expo.FileSystem.cacheDirectory+'/avatar')
My question is:
- The doc said that
cacheDirectory
is for one use only since it may be deleted any time on system’s discretion, does that mean in my case if I want to save this avatar permanently I have to usefileDirectory
instead in the above scenario? - When the app is deleted, will the saved file deleted with the app or is that something I have to explicitly handle? (in cases of cacheDirectory and fileDirectory)
- When user renews the avatar by taking new picture and
makeDirectoryAsync
is called again with the same exact command as written above for the second time and on, would it give me error saying the directory already exist or something like that? - When user take new picture and save in the
/avatar
directory, would it be saved as/avatar/image2
or will it overwrite/avatar/image1
?
Sorry for the basic questions, I just can’t seem to find any clue as to what happens in the background just based on the documentations…
And I know it’s weird, saving avatar to phone instead of to server then retrieving it from there but it’s just a hack-style decision by my project manager so yeah I have to find out how to do this properly. lol
Thanks in advance!
UPDATE:
based on #1245, readAsStringAsync()
could not be used for jpeg, is this still the case now? and if it is, is there any way I can make my use case work?