Home > database >  how to find absolute path of asset(uploaded image) in flutter?
how to find absolute path of asset(uploaded image) in flutter?

Time:10-16

 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..

CodePudding user response:

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.

  • Related