我正在尝试将图标上传到Firebase存储。当我尝试上传IconData时,出现错误,提示图标数据不是文件。我怎么解决这个问题?
final StorageReference storageReference = FirebaseStorage()
.ref()
.child(categoryRef.document().documentID + '.jpg');
final StorageUploadTask task = storageReference.putFile(icon);
最佳答案
在flutter中将图片文件上传到您的Firebase存储中的代码如下,
Future<String> uploadImage(File image) async {
StorageReference firebaseStorageRef = FirebaseStorage.instance.ref().child("Images/${DateTime.now().toIso8601String()}");
StorageUploadTask uploadTask = firebaseStorageRef.putFile(image);
StorageTaskSnapshot taskSnapshot = await uploadTask.onComplete;
String storagePath = await taskSnapshot.ref.getDownloadURL();
Uri finalPath = Uri.parse(storagePath);
return storagePath;
}
这肯定会将您的文件上传到Firebase存储,最后会返回您所存储文件的 URL路径。
关于firebase - 如何将图标上传到Firebase存储,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58103912/