0

I am creating an app that saves images locally through sqflite, I have soon found out that the images are being saved as temp which means that it will be deleted by the device and i'm not able to retrieve those images anymore. I have been coding to save it to the document directory of the app but it seems to fail and throw error

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: FileSystemException: Cannot copy file to '/data/user/0/com.example.e4psmap/cache/scaled_0d5d5070-70da-4f42-9055-c31a6ed8d3d51761448072222030817.jpg', path = '/data/user/0/com.example.e4psmap/app_flutter/scaled_0d5d5070-70da-4f42-9055-c31a6ed8d3d51761448072222030817.jpg' (OS Error: No such file or directory, errno = 2)

this is my code:

void getpic(ImageSource src) async{
    Uint8List byte;
    final picfile = await _imagepicker.getImage(
      source: src, imageQuality: 25
    );
    if(picfile != null){
      Directory appDir = await getApplicationDocumentsDirectory();
      String appdoc = appDir.path;
      final filename = path.basename(picfile.path);
      final local = File('${appdoc}/$filename');
      final lclfile = await local.copy(picfile.path);
    }
    // converted = picfile!.path;
    // setState(() {
    //   _imgfile = picfile!;
    // });
    Navigator.pop(context);
  }

Anyone knows why I am having this errors, and any fix for this error, Thank you

RalphIan
  • 3
  • 1
  • tried to check if folders `/data/user/0/com.example.e4psmap/cache/` and `/data/user/0/com.example.e4psmap/app_flutter/` do exist? – pskink Feb 15 '23 at 07:47
  • @pskink i have checked the directory and it said that it exist – RalphIan Feb 15 '23 at 08:13
  • and what files do they contain? – pskink Feb 15 '23 at 08:17
  • @pskink the `/data/user/0/com.example.e4psmap/cache/` have all temp images from the imagepicker while the `/data/user/0/com.example.e4psmap/app_flutter/` have this directories `/data/user/0/com.example.e4psmap/app_flutter/res_timestamp-1-1676442805802` and `/data/user/0/com.example.e4psmap/app_flutter/flutter_assets` – RalphIan Feb 15 '23 at 08:26
  • ok, in `local.copy(picfile.path)` variable `local` is a source file - a file you picked and want to copy to a new folder, you did the opposite: your `local` file is not yet existing file – pskink Feb 15 '23 at 08:53
  • @pskink it makes sense now.... ihave successfully saved my image to the path by altering my code... i have been putting the wrong variable the whole time..... thank you for your help :) – RalphIan Feb 15 '23 at 12:09

1 Answers1

-1

If you replace final with the corresponding class, the error will be very obvious.

ifredom
  • 979
  • 9
  • 6