如何在颤动中找到资产(上传图片)的绝对路径?
how to find absolute path of asset(uploaded image) in flutter?
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 是上传的图片
这个 FlutterAbsolutePath 不是 null 安全的,它是一个旧插件,请帮助我..
将此添加到您的 pubspec.yaml:
flutter_absolute_path:
git:
url: https://github.com/ValeriusGC/flutter_absolute_path.git
这是具有空安全支持的插件的分支。
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 是上传的图片
这个 FlutterAbsolutePath 不是 null 安全的,它是一个旧插件,请帮助我..
将此添加到您的 pubspec.yaml:
flutter_absolute_path:
git:
url: https://github.com/ValeriusGC/flutter_absolute_path.git
这是具有空安全支持的插件的分支。