React Native Image Upload的Firebase存储权限未知错误

时间:2018-05-14 05:39:58

标签: javascript firebase react-native firebase-storage

实际演示视频:https://www.youtube.com/watch?v=bYGi71am_tU

Firebase存储规则:

service firebase.storage {
  match /b/{bucket}/o {
    match /{allPaths=**} {
      allow write: if request.resource.size < 5 * 1024 * 1024
                   && request.resource.contentType.matches('image/.*');
    }
  }
}

enter image description here

我的blob图片:

Blob {
   "_data": Object {
     "blobId": "c526586a-0481-48ce-a77b-cc589052a443",
     "lastModified": 0,
     "name": "bbf91dba-8597-43d9-82b7-7a81887c3e5c.jpg",
     "offset": 0,
     "size": 32653,
     "type": "image/jpeg",
   },
}

Firebase存储错误:

FirebaseStorageError {
   "code_": "storage/unknown",
   "column": 31,
   "line": 17422,
   "message_": "Firebase Storage: An unknown error occurred, please check the error payload for server response.",
   "name_": "FirebaseError",
   "serverResponse_": "{
   \"error\": {
     \"code\": 400,
     \"message\": \"Permission denied. Could not access bucket crna-app-01.appspot.com. Please enable Firebase Storage for your bucket by visiting the Storage tab in the Firebase Console and ensure that you have sufficient permission to properly provision resources.\"
   }
 }",
   "sourceURL": "http://10.1.0.6:19001/node_modules/expo/AppEntry.bundle?platform=android&dev=true&minify=false&hot=false&assetPlugin=%2FUsers%2Fajinkyaborade%2Fprojects%2Fnative-apps%2Fmy-react-redux%2Fnode_modules%2Fexpo%2Ftools%2FhashAssetFiles",
 }

这是我的Expo RN app文件中的实际功能

async function uploadImageAsync(uri, uid, firebase) {

  const response = await fetch(uri);

  const blob = await response.blob();

  const ref = firebase
    .storage()
    .ref('users/' + uid)
    .child(uuid.v4());

  const snapshot = await ref.put(blob); // actual Firebase error comes here
  return snapshot.downloadURL;
}

非常感谢任何帮助:)

1 个答案:

答案 0 :(得分:0)

这是Firebase存储管理员的问题。

- 将firebase-storage@system.gserviceaccount.com添加为存储 ADMIN 完成