Flutter:Firebase Storage无法在发布模式下上传文件

时间:2018-09-18 02:19:41

标签: firebase dart flutter firebase-storage

说我有一个带有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)

我已经设置了Cloud Storage以允许在安全规则中进行读写。

1 个答案:

答案 0 :(得分:1)

我使用名为path_provider的软件包对其进行了修复,并更改了以下代码

之前:

<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjs/5.1.2/math.js"></script>

之后:

final Directory tempDir = Directory.systemTemp;