我在 Firebase 存储中上传文本文件并将一些数据存储在 Firebase 实时数据库中。做上述事情没有问题。此外,我能够获取 firestorage 中存在的所有文件以及文本文件的 URL。 但我无法读取文本文件中的内容。我正在使用下面的代码来获取数据在调用以下代码之前,我在 init 中调用 getfileDetails() 方法将所有数据存储在 fileDetailList 中 this.uploadService.fileDetailList.snapshotChanges().subscribe( list => { console.log("before fileListDetails= "); this.fileListDetails = list.map((item) => { return item.payload.val(); }); console.log("fileListDetails= " + JSON.stringify(this.fileListDetails)); //logs attached below this.FileDetailsList = this.fileListDetails; this.FileDetailsList.forEach((item) => { console.log("item= " + item.imgUrl); // to get the text from file this.http.get<string>(item.imgUrl).subscribe( (item11)=>{ console.log("file read= "+item11); //getting error Here } ); }); } );我的 uploadService.ts 方法fileDetailList:AngularFireList<any>;constructor(private firebase:AngularFireDatabase) { } getfileDetails() { console.log("getfileDetails"); this.fileDetailList=this.firebase.list('FileDetails'); }日志详细信息fileListDetails= [{"caption":"nkn,","category":"hello.txt","imgUrl":"https://firebasestorage.googleapis.com/...."}]当我直接在浏览器中点击 imgUrl 时,我能够获取文本
1 回答
![?](http://img1.sycdn.imooc.com/54584cfb0001308402200220-100-100.jpg)
慕村9548890
TA贡献1884条经验 获得超4个赞
您需要告诉 http 客户端您期望的是纯文本响应,而不是默认的 JSON
请注意,当指定responseType
JSON 以外的值时,您不需要像this.http.get<MyType>
已经指定的那样提供通用参数。
this.http.get(item.imgUrl, {responseType: "text"}).subscribe(...)
参考: https ://angular.io/guide/http#requesting-data-from-a-server
添加回答
举报
0/150
提交
取消