Flutter-iOS when apps update / recompile stored image is missing
Asked Answered
A

2

6

Hi forgive my English and also a newbie on flutter iOS, I have an app on flutter on iOS that users can take pictures and videos from their camera and gallery I'm using the image_picker package this has no problem, then I save it on the on its Application Documents Directory I tried following this guide

my code for getting the application directory is this

Directory _appDocDir;
_appDocDir = await getApplicationDocumentsDirectory();
final Directory _appMediaDir = Directory('${_appDocDir.path}/Pictures/');
return _appMediaDir;

added with a 'Pictures' directory this will give a path of

/Users/macman/Library/Developer/CoreSimulator/Devices/96060868-7E5C-4E15-9900-4D1D4B0B5ACE/data/Containers/Data/Application/BE7728A6-FF15-498E-91A0-A96A3DDE5B31/Documents/Pictures/D_IMG_0002.JPG  

from the iOS-simulator I save it and put in the database, and after re-compiling the app or doing a build update the previewing the image/video path is not found anymore. I tried to save another image on this build it and gave this path

/Users/macman/Library/Developer/CoreSimulator/Devices/96060868-7E5C-4E15-9900-4D1D4B0B5ACE/data/Containers/Data/Application/9D634D91-07B8-43BE-8646-2A55833322DF/Documents/Pictures/D_IMG_0005.JPG

I noticed earlier path this part "/BE7728A6-FF15-498E-91A0-A96A3DDE5B31/" is changed every time I re-compile the app or make an update from the iOS device the image is not found. What is the most practice for this users able to save image am I doing it wrong?

Update: I tried changing my logic to change the saved path to only the base name (D_IMAGE_0005.JPG) then when previewing the image will call the current application documents directory but this does not work also.

Thank You

Aerodrome answered 6/6, 2021 at 12:51 Comment(0)
R
10

Hi don't save the whole path given by the getApplicationDocumentsDirectory() on you record, instead save only the basename, and every time you preview/load the image call the

getApplicationDocumentsDirectory() + 'Pictures/<basename>',

every time the app gets updated or recompiled on the iOS the appid changes, that is why your path fails to load on a recompile.

Radiolocation answered 7/6, 2021 at 2:7 Comment(2)
I need to read more to understand the reasons behind this path change on each iOS build, just to tell this could be a proper way to solve it. In the meantime, I can tell this does solve the issue. Just for the record, it happens not only on the iOS simulator as stated by the OP. It happens as well building to the device no matter if in debug or in release mode. Thanks!Odoacer
This saved my day - should be the accepted answerScurrility
D
0

iOS removes the documents directory every time you reinstall the app if your application is running on a sandbox environment.

Please refer to this stackoverflow question for more clarification

Doggo answered 6/6, 2021 at 13:40 Comment(2)
This doesn't relate to the question - the OP is not uninstalling / reinstalling the app, just deploying a new build (in which case, the documents directory is not removed)Scurrility
What does deploying a new build mean? Isn't it reinstalling?Doggo

© 2022 - 2024 — McMap. All rights reserved.