首页 > 解决方案 > RNFirebase 需要身份验证才能下载/上传文件

问题描述

我正在尝试将我的项目与react-native-firebase. Signin/Signup工作正常,现在我坚持文件下载和上传。

我有以下 RN 组件:

class ScheduleCarPoolScreen extends React.Component {
  days = 5;

  state = {
    childAvatar: '',
    childName: '',
    childAge: 10,
  };

  render() {
    return (
      <View style={styles.container}>
        <Avatar
          rounded
          xlarge
          source={{uri: "/some/resource.jpg"}}
          onPress={() => {
            ImagePicker.showImagePicker(null, async (response) => {

              let storage = firebase.storage();
              let bucket = storage.ref();
              bucket.downloadFile('/profile.jpg').then((val) => {
                debugger;
                console.log(`RECEIVED: ${JSON.stringify(val)}`);
              }).catch((err) => {
                debugger;
                console.log(`ERROR: ${err.message}`);
              });

            });
          }}
          activeOpacity={0.7}
          containerStyle={{justifyContent: "center"}}
        />
      </View>
    );
  }
}

因此,通过图像下载,我收到以下错误: ERROR: User is not authorized to perform the desired action.. 我也尝试在下载文件之前执行授权,但这也不起作用。

事实上,如果我尝试将一些文件上传到 firebase 商店,我会收到另一种带有以下错误对象的异常:

{
  "framesToPop":1,
  "code":"storage/unknown",
  "nativeStackIOS":[
      "0   app                                 0x0000000109456126 RCTJSErrorFromCodeMessageAndNSError + 134",
      "1   app                                 0x00000001093e6953 __41-[RCTModuleMethod processMethodSignature]_block_invoke_2.218 + 179",
      "2   app                                 0x0000000109fd6dcd -[RNFirebaseStorage promiseRejectStorageException:error:] + 1101",
      "3   app                                 0x0000000109fd5481 __74-[RNFirebaseStorage addUploadObservers:uploadTask:path:resolver:rejecter:]_block_invoke.446 + 193",
      "4   libdispatch.dylib                   0x0000000114e5a73b _dispatch_call_block_and_release + 12",
      "5   libdispatch.dylib                   0x0000000114e5b779 _dispatch_client_callout + 8",
      "6   libdispatch.dylib                   0x0000000114e65778 _dispatch_main_queue_callback_4CF + 1279",
      "7   CoreFoundation                      0x000000011412fc99 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9",
      "8   CoreFoundation                      0x00000001140f3ea6 __CFRunLoopRun + 2342",
      "9   CoreFoundation                      0x00000001140f330b CFRunLoopRunSpecific + 635",
      "10  GraphicsServices                    0x00000001163f4a73 GSEventRunModal + 62",
      "11  UIKit                               0x00000001107410b7 UIApplicationMain + 159",
      "12  app                                 0x00000001090cde4f main + 111",
      "13  libdyld.dylib                       0x0000000114ed0955 start + 1"
  ],
  "domain":"RCTErrorDomain",
  "userInfo":null,
  "message":"An unknown error has occurred.",
  "stack":"Error: An unknown error has occurred.
at createErrorFromErrorData (blob:http://localhost:8081/d39215c6-4339-4eff-bfa8-0e8644a01975:6160:17)
at blob:http://localhost:8081/d39215c6-4339-4eff-bfa8-0e8644a01975:6112:27
at MessageQueue.__invokeCallback (blob:http://localhost:8081/d39215c6-4339-4eff-bfa8-0e8644a01975:6554:18)
at blob:http://localhost:8081/d39215c6-4339-4eff-bfa8-0e8644a01975:6299:18
at MessageQueue.__guardSafe (blob:http://localhost:8081/d39215c6-4339-4eff-bfa8-0e8644a01975:6467:11)
at MessageQueue.invokeCallbackAndReturnFlushedQueue (blob:http://localhost:8081/d39215c6-4339-4eff-bfa8-0e8644a01975:6298:14)
at http://localhost:8081/debugger-ui/debuggerWorker.js:72:58"
}

有没有人可以告诉如何正确上传/执行身份验证?

标签: javascriptreact-nativereact-native-firebase

解决方案


推荐阅读