Javascript 显示.txt文件';反应中的硫含量
我希望通过dropbox API显示dropbox中存储的.txt文件的内容 我已经通过创建src url blob来浏览和显示图像了 我通过研究发现的所有示例都使用jQuery或ajax。既然我已经通过API访问了这些文件,那么肯定不需要再次调用dropbox服务器了吧 我尝试使用Javascript 显示.txt文件';反应中的硫含量,javascript,reactjs,dropbox-api,Javascript,Reactjs,Dropbox Api,我希望通过dropbox API显示dropbox中存储的.txt文件的内容 我已经通过创建src url blob来浏览和显示图像了 我通过研究发现的所有示例都使用jQuery或ajax。既然我已经通过API访问了这些文件,那么肯定不需要再次调用dropbox服务器了吧 我尝试使用embed标记,但浏览器随后尝试下载文件 如何使用Dropbox API在react中显示txt文件的内容? class Project extends React.Component{ constructor
embed
标记,但浏览器随后尝试下载文件
如何使用Dropbox API在react中显示txt文件的内容?
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>
);
}
}
类项目扩展React.Component{
构造函数(){
超级();
此.state={
文件源:[],
}
}
componentDidMount(){
var=这个;
风险值来源=[];
var link=“/”+this.props.title;
filesListFolder({path:link})
.然后(功能(响应){
...
...
//呼叫dropbox
...
...
var newUrls=window.URL.createObjectURL(response.fileBlob);
推送(newurl);
})
.然后(函数(){
那是一个州({
fileSource:sources,
});
});
}
});
}
render(){
如果(!this.state.fileSource.length)
返回null;
让text=this.state.fileSource.map((el,i)=>
)
返回(
{text}
);
}
}
更新:我遇到了上一个问题,它从对象创建一个fileBlob,然后使用FileReader()
和readAsText()
显示内容。您的代码显示您使用的是返回文件元数据的filelistfolder
。如果需要文件内容,则需要调用所需的文件。的可能重复项