【问题标题】:putFile is not a functionputFile 不是函数
【发布时间】:2020-02-29 21:07:29
【问题描述】:

我是 React Native 的新手,正在尝试为慈善机构创建一个应用程序。

我在尝试将使用相机拍摄的图像存储在 Firebase 存储中时遇到问题。

代码片段在下面,查看控制台日志,一切看起来都符合我的预期,也在下面。

我得到的错误是“imageRef.Putfile 不是函数”。

任何帮助将不胜感激。

控制台日志输出

ref, image, imageName breadalert-86646.appspot.com file:///data/user/0/host.exp.exponent/cache/ExperienceData/%2540anonymous%252Frn-complete-guide-10d15822-a070-46a4-a2a0-98550f263c74/ImagePicker/8211188f-6bf4-4aaf-a3ba-e187b1e3707f.jpg CKhLXQlDUtUvKotCYQmJLmOeI1s247
getting storage ref of breadalert-86646.appspot.com
firebaseStorageRef is gs://breadalert-86646.appspot.com/
Image is gs://breadalert-86646.appspot.com/CKhLXQlDUtUvKotCYQmJLmOeI1s247
Image Path is file:///data/user/0/host.exp.exponent/cache/ExperienceData/%2540anonymous%252Frn-complete-guide-10d15822-a070-46a4-a2a0-98550f263c74/ImagePicker/8211188f-6bf4-4aaf-a3ba-e187b1e3707f.jpg

代码片段

 saveImage = (ref, image, imageName, onSuccess, onError) => {


  console.log ('ref, image, imageName ' + ref + ' ' + image + ' ' + imageName);
  console.log ('getting storage ref of ' + ref);

  firebaseStorageRef = firebase.storage().ref();

  console.log ('firebaseStorageRef is ' + firebaseStorageRef);

  imageRef = firebaseStorageRef.child(imageName);
  console.log ('Image is ' + imageRef);
  console.log ('Image Path is ' + image);



  imageRef.putFile (image.path, {contentType: 'image/jpeg'}).then(function(){
      return imageRef.getDownloadURL();
  }).then(function(url){
    console.log ("Image url", {url:url});
      onSuccess(url);
  }).catch(function(error){
    console.log ("Error while saving the image.. ", error);
      onError(error);
  });
}

【问题讨论】:

  • 你试过把putFile改成put吗?

标签: javascript firebase react-native firebase-storage


【解决方案1】:

您的imageRefReference 类型的对象。看看链接的 API 文档 - 它没有名为 putFile() 的方法。这就是错误消息告诉您的内容。

如果你想上传文件,你应该使用名为put()的方法而不是documentation中描述的方法。

【讨论】:

    猜你喜欢
    • 2018-05-29
    • 1970-01-01
    • 2018-01-07
    • 1970-01-01
    • 1970-01-01
    • 2020-03-28
    • 1970-01-01
    • 1970-01-01
    • 2017-05-06
    相关资源
    最近更新 更多