我試圖重新上傳/移動一個已經存在于Firebase存盤中的檔案到同一個Firebase存盤中不同的檔案夾中的另一個路徑,并使用redux-actions改變其名稱,所以檔案被上傳,但它損壞了=>這意味著當我試圖打開它時,它打開時沒有資料/圖片,圖片的大小9B。
代碼:
//upload the same file with new path and remove the old file。
let uploadAndDeletePromises = fileArr.map(
(fileData, index) =>
儲物Ref
//newpaths=folderName/FolderWithIdName/fileName__docId.png
.child(newFilesPaths[index] )
.put(
// filesToUpload資料顯示在以下圖片中。
filesToUpload[index],
// metadata={customMetadata:
// {uplaoderId:"",PrId:"" }
metadata[index]
)
.then(() =>)
//洗掉舊的路徑。
儲物Ref
//fileData.path -> the old path
//FolderName/folderWithIdName/fileName.png
.child(fileData.path)
.delete()
)
);
return Promise.all(uploadAndDeletePromises)。
從原來的filesToUpload的結果,效果很好,這些是當我第一次上傳時:
來自filesToUpload的結果,我想從Firebase存盤重新上傳至Firestore存盤的另一個路徑,這些是我試圖重新上傳至不同路徑時的情況:
誰有處理/將檔案從一個路徑移到另一個路徑并改變其名稱的經驗,使用react js動作,firebase存盤,而不是node js。
uj5u.com熱心網友回復:
移動檔案的功能是在服務器端庫中。
1.下載檔案
2.上傳檔案到新的位置2.上傳檔案到新的位置
。3.洗掉以前的檔案(如果需要的話)
看起來你對如何上傳新檔案和洗掉以前的檔案有一個想法,但在下載以前的檔案時遇到了問題(這就是為什么上傳的是 9B 檔案)。
根據檔案,您將這樣下載檔案
。storageRef.child('path/to/file').getDownloadURL()。
.then((url) =>/span> {
// `url`是檔案的下載URL。
//這可以直接下載:
var xhr = new XMLHttpRequest() 。
xhr.responseType = 'blob'。
xhr.onload = (event) => {
var blob = xhr.response;
//在此插入上傳和洗掉代碼。
};
xhr.open('GET', url)。
xhr.send()。
})
.catch((error) =>/span> {
//處理任何錯誤。
});
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/325755.html
標籤:


