亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何以角度從 Firebase 存儲中讀取文本文件

如何以角度從 Firebase 存儲中讀取文本文件

婷婷同學_ 2022-10-21 14:21:10
我在 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 回答

?
慕村9548890

TA貢獻1884條經驗 獲得超4個贊

您需要告訴 http 客戶端您期望的是純文本響應,而不是默認的 JSON

請注意,當指定responseTypeJSON 以外的值時,您不需要像this.http.get<MyType>已經指定的那樣提供通用參數。

this.http.get(item.imgUrl, {responseType: "text"}).subscribe(...)

參考: https ://angular.io/guide/http#requesting-data-from-a-server


查看完整回答
反對 回復 2022-10-21
  • 1 回答
  • 0 關注
  • 128 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號