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

377

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.

Share:
377
Verney Kiok Kan
Author by

Verney Kiok Kan

Updated on December 01, 2022

Comments

  • Verney Kiok Kan
    Verney Kiok Kan over 1 year

    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

  • maganap
    maganap over 2 years
    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!