繁体   English   中英

无法从颤振网络将图像上传到 Firebase 存储

[英]Can't upload image to Firebase Storage from flutter web

所以我试过这个来获取图像并上传它:

var file;
      html.InputElement uploadInput = html.FileUploadInputElement()
        ..accept = "image/*";
      uploadInput.click();
      uploadInput.onChange.listen((event) {
        file = uploadInput.files.first;
        final reader = html.FileReader();
        reader.readAsDataUrl(file);
        reader.onLoadEnd.listen((event) async {
          print("done");
          StorageReference storageReference = FirebaseStorage.instance
              .ref()
              .child('${widget.uid}/${DateTime.now()}');
          StorageUploadTask uploadTask = storageReference.putData(file);
          await uploadTask.onComplete;
          print('File Uploaded');
          print(storageReference.path);
          storageReference.getDownloadURL().then((fileURL) {
            setState(() {
              _uploadedFileURL = fileURL;
              
            });
          });
        });
      });

如教程中所示,但是这家伙使用 .put() 而不是 putData() 但它现在已弃用,因此在使用 .put() 时我得到:

应为“文件”类型的值,但得到“文件$”类型的值

和 .putData() 我得到:

应为“Uint8List”类型的值,但得到“File$”类型的值

有什么想法可以转换 File$ 或从 Flutter Web 用户直接导入 File 或 Uint8List 吗? 谢谢

尝试reader.readAsArrayBuffer(file)storageReference.putData(reader.result)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM