未处理的异常:FileSystemException:无法打开文件,路径 = '(JPEG image.jpeg)'

时间:2021-04-30 06:05:36

标签: ios flutter file dart mobile

我编写了一行代码来减小从本地数据存储中获取的文件(图像)的大小(使用文件选择器)。这就是代码执行时发生的情况

(IOS 模拟器)

未处理的异常:FileSystemException:无法打开文件,路径 = '(JPEG image.jpeg)'

错误抖动

打开文件

  void _openFileExplorer() async {
    setState(() => _loadingPath = true);
    try {
      _directoryPath = null;
      _paths = (await FilePicker.platform.pickFiles(
        type: _pickingType,
        allowMultiple: _multiPick,
        allowedExtensions: ['jpg', 'pdf', 'doc', 'docx', 'png', 'jpeg'],
      ))

          ?.files;
    } on PlatformException catch (e) {
      print("Unsupported operation" + e.toString());
    } catch (ex) {
      print(ex);
    }

    if (!mounted) return;
    setState(() {
      _loadingPath = false;
      _fileName = _paths!= null ? _paths.map((e) => e.name).toString() : '...';

      PlatformFile file = _paths.first;
      print(file.size);
      var snackBar = SnackBar(content: Text('${file.size}' + " byte"),
        backgroundColor: Colors.green);
      _scaffoldKey.currentState.showSnackBar(snackBar);
    });
   
  }
 compressingPhoto() async {

    final tDirectory = await getTemporaryDirectory();
    final path = tDirectory.path;
    //final path = tDirectory.path;

    File file = File(_fileName);
    ImD.Image mImageFile = ImD.decodeImage(file.readAsBytesSync());
    //ImD.Image smallerImage =ImD.copyResize(mImageFile, 5000);
    final compressedImageFile = File('$path/img_$_fileName.jpg')..writeAsBytesSync(ImD.encodeJpg(mImageFile,
        quality: 88));
    setState(() {
      file = compressedImageFile;
      print(file.lengthSync);
    });
  }

  controlUploadSave()async{
    
    await compressingPhoto();

  }

0 个答案:

没有答案