ios – How do I store an image url coming from Flutter Image Picker in the Database for later use


I have setup the code according to Flutter Image Picker documentation.

https://pub.dev/packages/image_picker

The method seen below does exactly as it should and it retrieves a url to the image selected from the picker.

Future handleEditProfilePic() async {
  final XFile? image = await picker.pickImage(
    source: ImageSource.gallery,
    maxWidth: 300,
    maxHeight: 300,
    imageQuality: 50,
  );

  setState(() {
    _image = image;
  });
}

Here is a sample of the type of url it returns:

/private/var/mobile/Containers/Data/Application/7021FEB0-EE3A-48CE-8E77-3F2A5D32867C/tmp/image_picker_B8C28D76-F5E7-48B7-B280-05013590CAC8-9304-0000102466C56AE8.jpg

After getting the url I am able to render the image properly. The code that renders the image is seen below.

Image.file(File(_image!),fit: BoxFit.cover);

Everything is good so far. Next I send the url to the database. Later after closing the application, reopening it and retrieving the url from the database attempting to use it, it fails.

I am guessing the url generated by the Image Picker is only existing within the lifecycle of the app and once closed it is no longer a valid url. I am guessing this only the url seem to be have a tmp segment possibly indicating temp storage.

I have looked at the documentation and have searched the internet looking at one tutorial after another trying to figure out what I am missing. Most all the tutorials are either showing instructions from older versions of the picker or they don’t show anything about storing urls and getting the image later using the url.

Any assistance is appreciated. Thanks in advance.

Latest articles

spot_imgspot_img

Related articles

Leave a reply

Please enter your comment!
Please enter your name here

spot_imgspot_img