Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.8k views
in Technique[技术] by (71.8m points)

camera - Flutter: Unhandled Exception: FileSystemException: Creation failed, path = 'Directory: '' (OS Error: Read-only file system, errno = 30)

I already googling and the solution that I found are using path_provider, add permission in AndroidManifest.xml and yes I already try that. But still error in mine.

This is my function

  Future<File> _takePicture() async {
    Directory root = await getTemporaryDirectory(); // this is using path_provider
    String directoryPath = '$root/bozzetto_camera';
    await Directory(directoryPath).create(recursive: true); // the error because of this line
    String filePath = '$directoryPath/${DateTime.now()}.jpg';
    try {
      await _cameraController.takePicture(filePath);
    } catch (e) {
      return null;
    }
    return File(filePath);
  }

This is my AndroidManifest.xml

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

    <application
        ...
        android:requestLegacyExternalStorage="true">
        
        ...

    </application>

And this is full of the log.

E/flutter (14879): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: FileSystemException: Creation failed, path = 'Directory: '' (OS Error: Read-only file system, errno = 30)
E/flutter (14879): #0      _Directory.create.<anonymous closure> (dart:io/directory_impl.dart:117:11)
E/flutter (14879): #1      _rootRunUnary (dart:async/zone.dart:1198:47)
E/flutter (14879): #2      _CustomZone.runUnary (dart:async/zone.dart:1100:19)
E/flutter (14879): #3      _FutureListener.handleValue (dart:async/future_impl.dart:143:18)
E/flutter (14879): #4      Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:696:45)
E/flutter (14879): #5      Future._propagateToListeners (dart:async/future_impl.dart:725:32)
E/flutter (14879): #6      Future._completeWithValue (dart:async/future_impl.dart:529:5)
E/flutter (14879): #7      Future._asyncCompleteWithValue.<anonymous closure> (dart:async/future_impl.dart:567:7)
E/flutter (14879): #8      _rootRun (dart:async/zone.dart:1190:13)
E/flutter (14879): #9      _CustomZone.run (dart:async/zone.dart:1093:19)
E/flutter (14879): #10     _CustomZone.runGuarded (dart:async/zone.dart:997:7)
E/flutter (14879): #11     _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1037:23)
E/flutter (14879): #12     _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
E/flutter (14879): #13     _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You need to modify the directory path.

Just change the code

from

String directoryPath = '$root/bozzetto_camera';

to

String directoryPath = root.path + '/bozzetto_camera';

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...