【发布时间】:2021-03-23 23:42:43
【问题描述】:
我正在使用文件选择器插件从设备中选择文件。该文件是在 PlatformFile 的数据类型中选择的,但我想将文件发送到 Firebase 存储,我需要一个常规文件。如何将 PlatformFile 转换为 File 以便将其发送到 Firebase Storage?代码如下:
PlatformFile pdf;
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
void _trySubmit() async {
final isValid = _formKey.currentState.validate();
if (isValid) {
_formKey.currentState.save();
final ref = FirebaseStorage.instance
.ref()
.child('article_pdf')
.child(title + '-' + author + '.pdf');
await ref.putFile(pdf).onComplete; // This throws an error saying that The argument type 'PlatformFile' can't be assigned to the parameter type 'File'
}
}
void _pickFile() async {
FilePickerResult result = await FilePicker.platform.pickFiles(
type: FileType.custom,
allowedExtensions: ['pdf'],
);
if (result != null) {
pdf = result.files.first;
}
}
【问题讨论】:
标签: flutter firebase-storage flutter-dependencies filepicker