说我有一个有onPressed: ()=> uploadFile(_image.path) // File _image = new File();
的凸起按钮,这是我的功能。
Future<Null> uploadFile(String filepath) async {
final String fileName = '$myImage.jpg';
final ByteData bytes = await rootBundle.load(filepath);
final Directory tempDir = Directory.systemTemp;
final File file = File('${tempDir.path}/$fileName');
file.writeAsBytes(bytes.buffer.asInt8List(), mode: FileMode.write);
final StorageReference storageRef =
FirebaseStorage.instance.ref().child('justAnImage/$fileName');
final StorageUploadTask task = storageRef.putFile(file);
final Uri downloadUrl = (await task.future).downloadUrl;
path = downloadUrl.toString();
return path;
}
它会在调试模式下将图像上传到Firebase存储,但是在发布模式下。它给了我一个错误。 Cannot open file, path = '/data/local/tmp/myImage123.jpg' (OS Error: Permission denied, errno = 13)
我已经设置了我的云存储以允许读写安全规则。
我用一个名为path_provider的包修复它并更改以下代码
之前:
final Directory tempDir = Directory.systemTemp;
后:
final Directory tempDir = await getTemporaryDirectory();