在 React 中显示 .txt 文件的内容

Display .txt file's content in React

我希望通过保管箱 API.

显示存储在保管箱中的 .txt 文件的内容

我已经通过创建 src url blob

来完成并显示图像

我通过研究找到的所有示例都使用 jQuery 或 ajax。由于我已经通过 API 访问这些文件,所以肯定不需要再次调用保管箱服务器吗?

我尝试使用 embed 标签,但浏览器随后尝试下载文件。

如何使用 Dropbox 在 React 中显示 txt 文件的内容API?

class Project extends React.Component{

  constructor(){
    super();
    this.state = {
    fileSource: [],
  }
}

componentDidMount(){
  var that = this;
  var sources = [];
  var link = "/"+this.props.title;

  dbx.filesListFolder({path: link})
    .then(function(response) {

      ...
      ...
      //call to dropbox
      ...
      ...

        var newUrls=window.URL.createObjectURL(response.fileBlob);
        sources.push(newUrls);
    })

    .then(function(){
        that.setState({
          fileSource: sources,
        });

      });
    }
  });
}

render() {

  if(!this.state.fileSource.length)
    return null;

    let text = this.state.fileSource.map((el, i) =>
      <embed src={el}/>
    )

    return (
      <div className="projectWrapper">
        {text}
      </div>
   );
  }
}

更新:我遇到了 上一个问题,该问题从对象创建一个 fileBlob,然后使用 FileReader()readAsText() 来显示内容。