1

我正在尝试在聊天中发送图像或 txt 文件。我正在使用 SendBird react-native sdk ( https://docs.sendbird.com/javascript )。

FilePickerManager.showFilePicker(null, (response) => {
      console.log('Response = ', response);
      if (Platform.OS === 'android') {
        sb.enableStateChange();
      }
      if (response.didCancel) {
        console.log('User cancelled file picker');
      }
      else if (response.error) {
        console.log('FilePickerManager Error: ', response.error);
      }
      else if (response.customButton) {
        console.log('User tapped custom button: ', response.customButton);
      }
      else {
        debugger;
        let source = { uri: response.uri };
       const _SELF=this;
        if (response.name) {
                  source['name'] = response.fileName
                } else {
                  paths = response.uri.split("/")
                  source['name'] = paths[paths.length - 1];
                }
               
                if (response.type) {
                  source['type'] = response.type;
                } 

                console.log('source =  ',source);
                const CHECK_IMAGE_URI_INTERVAL = Platform.OS === 'android' ? 300 : 100;
                
                        // This is needed to ensure that a file exists
                        setTimeout(() => {
                          // Use getSize as a proxy for when the image exists
                          Image.getSize(
                            response.uri,
                            () => {
                _SELF.state.channel.sendFileMessage(source, function (message, error) {
                  if (error) {
                    console.log(error);
                    return;
                  }
  
                  var _messages = [];
                  _messages.push(message);
                  if (_SELF.state.lastMessage && message.createdAt - _SELF.state.lastMessage.createdAt > (1000 * 60 * 60)) {
                    _messages.push({ isDate: true, createdAt: message.createdAt });
                  }
  
                  var _newMessageList = _messages.concat(_SELF.state.messages);
                  _SELF.setState({
                    messages: _newMessageList,
                    dataSource: _SELF.state.dataSource.cloneWithRows(_newMessageList)
                  });
                  _SELF.state.lastMessage = message;
                });
                
        this.setState({
          file: response
        });
      }
    );
  }, CHECK_IMAGE_URI_INTERVAL);
      }
    });

错误堆栈跟踪

Can currently only create a Blob from other Blobs
Invariant Violation: Can currently only create a Blob from other Blobs↵    at invariant (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:1636:15)
at http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:13957:7
at Array.forEach (<anonymous>)↵    at new Blob (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:13956:11)
at http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:68688:250
at z.checkRouting (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:68683:16)
at t (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:68686:154)
at z.uploadFile (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:68876:9)
at b.M.sendFileMessage (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:67978:182)
at http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:85380:35
4

0 回答 0