Ad

How To Find Absolute Path Of Asset(uploaded Image) In Flutter?

- 1 answer

 Asset asset = resultList![i]; 
     String fileName = asset.name!;
     final filePath = await FlutterAbsolutePath.getAbsolutePath(asset.identifier); 
     var f = File('${File(asset.identifier!).absolute.path}/$fileName');  
      
                 
      ```  print('FILE ABS :$filePath');```
   FILE ABS :/data/user/0/com.appname.com/cache/IMG_1634398462781.png
                
                             
                  print('FILE :$f');
                     FILE:File:'/content://media/external/images/media/18/JPEG_20211016_172650_1080214037652379427.jpg'
                    
                                  var file = File(filePath);
                                      var compressedFile;
                                      if (file.lengthSync() > 300000) {
                                        compressedFile = await FlutterImageCompress.compressWithFile(
                                          file.absolute.path,
                                          quality: 25,
                                        );
                                      }
                                      Network.MultipartFile multipartFile = await Network.MultipartFile.fromBytes(compressedFile != null ? compressedFile:file.readAsBytesSync(),filename: fileName);
                    
        

asset is the image which is uploaded
This FlutterAbsolutePath is not null safe and its a old plugin, Please help me on this..

Ad

Answer

Add this to your pubspec.yaml:

flutter_absolute_path:
        git:
          url: https://github.com/ValeriusGC/flutter_absolute_path.git

This is a fork of the plugin with null safety support.

Ad
source: stackoverflow.com
Ad