首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >上传图片颤动存储

上传图片颤动存储
EN

Stack Overflow用户
提问于 2020-02-29 18:27:46
回答 1查看 62关注 0票数 0

我在我的应用中使用了'image_picker_web/image_picker_web.dart‘。现在,当我选择图像时,这个图像显示,它是工作。但是,当我尝试将图像保存到存储器中时,没有任何反应。

代码语言:javascript
复制
Uint8List _image1;

Future getImg() async {
Uint8List tempImg = await ImagePickerWeb.getImage(asUint8List: true);

if (tempImg != null) {
  setState(() {
    // debugPrint(tempImg.toString());
    _image1 = tempImg;
  });
}}

保存在存储中:

代码语言:javascript
复制
void uploadImg() async {
final StorageReference productImg =
    FirebaseStorage.instance.ref().child('ProductImg');
var timekey = DateTime.now();
final StorageUploadTask uploadTask =
    productImg.child(timekey.toString() + 'jpg').putData(_image1);
var imageUrl = await (await uploadTask.onComplete).ref.getDownloadURL();
url = imageUrl.toString();
print('Image Url' + url);}

按钮:

代码语言:javascript
复制
RaisedButton(
   onPressed: () {
     uploadImg();
 }

我做错了什么?

EN

回答 1

Stack Overflow用户

发布于 2020-02-29 23:09:31

试一试:

代码语言:javascript
复制
final file = File.fromRawPath(uint8list);
final ref = FirebaseStorage.instance.ref().child("users/some_id/ProductImg.jpg");
final task = ref.putFile(file, StorageMetadata(contentType: "image/png"));
final snapshot = await task.onComplete;
if (snapshot.error != null) throw snapshot.error;
final downloadURL = await snapshot.ref.getDownloadURL();
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60464107

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档