![](/img/trans.png)
[英]how can i upload file to firebase storage and display the download URL?
[英]How can I get image download url from firebase storage file, if I know what name it will be stored under?
我有一個 firebase 調整圖像擴展名,一旦圖像上傳到特定文件夾(在我的情況下為 profilePhotos),它就會將該圖像轉換為更小的尺寸(在我的情況下為 320x320),並在名稱末尾添加“_320x320” 。
最初,我有一個雲函數創建 url 並通過getSignedUrl()更新 firestore 中的相關文檔,直到我意識到所有簽名的 url 在 7 天后過期。
這就是我從前端獲取原始圖片下載網址的方式:
uploadTask.on(
"state_changed",
(snapshot) => {
const progress =
(snapshot.bytesTransferred / snapshot.totalBytes) * 100;
setProgress(progress);
},
(error) => {
console.log("error" + error);
},
() => {
getDownloadURL(userUploadRef).then(async (downloadUrl) => {
// code that updates the document in firestore by adding the url
如果我知道原始圖像名稱和調整大小的圖像名稱之間的唯一區別是一個以_320x320 結尾,我是否可以更改下載 url 以獲取我的圖像的下載 url,如果可以,怎么辦?
僅當訪問令牌從原始圖像傳遞到調整大小的圖像時,更改下載 URL 才有效,我不確定是否是(擴展在某些時候支持,但我記得它存在問題) .
更好的方法是通過單獨調用getDownloadURL
並引用正確的路徑來確定調整大小的圖像名稱的下載 URL:
const storage = getStorage();
const resizedRef = ref(storage, 'images/stars_320x320.jpg');
getDownloadURL(resizedRef).then(...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.