reactjs 如果我在上传开始后超过400ms暂停上传,Firebase Cloud Firestore将抛出“未知错误”

vlju58qv  于 2023-01-17  发布在  React
关注(0)|答案(1)|浏览(144)

我当时正在试用firebase,我写了一段代码来试用云存储服务,但是我意识到如果我在启动后400 - 500 ms之后暂停文件上传,它会抛出一个未知的错误。

async function uploadFile() {
    //file comes from a file a file input html element
    const uploadTask = uploadBytesResumable(ref(cloudStorage, `videos/${file.name}`),file);

    uploadTask.on("state_changed",(snapshot) => {
        const uploadProgress = (snapshot.bytesTransferred / snapshot.totalBytes) * 100;
            
        //I update a state
        setProgress(Math.floor(uploadPercent));

    switch (snapshot.state) {
    case "paused":
        console.log("Upload paused");
    break;
    case "running":
        console.log("Upload resumed");
    break;
    }
},
(e) => {
    console.log("an error occurred...", e.serverResponse, e);
 },
() => {
    console.log("upload completed!");
     });

    setTimeout(() => {
    uploadTask.pause();
    }, 400); 
     //result => download is paused with no error

    setTimeout(() => {
    uploadTask.pause();
    }, 500); 
    //result => unknown error occurred

}

错误堆栈...

an error occurred... <empty string> FirebaseError: Firebase Storage: An unknown error occurred, please check the error payload for server response. (storage/unknown)
    FirebaseError errors.ts:85
    StorageError error.ts:40
    unknown error.ts:126
    backoffDone request.ts:163
    triggerCallback backoff.ts:67
    responseHandler backoff.ts:91
    node_modules bundle.js:45348
    promise callback*doTheRequest request.ts:113
    node_modules bundle.js:45038
    setTimeout handler*callWithDelay backoff.ts:72
    start backoff.ts:136
    start_ request.ts:184
    node_modules bundle.js:45309
    NetworkRequest request.ts:76
    makeRequest request.ts:273
    _makeRequest service.ts:309
    node_modules bundle.js:47029
    node_modules bundle.js:46971
    promise callback*_resolveToken task.ts:211
    _continueUpload task.ts:296
    node_modules bundle.js:46956
    setTimeout handler*_start task.ts:195
    completeTransitions_ task.ts:477
    node_modules bundle.js:46992
    promise callback*./node_modules/ bundle.js:46988
    node_modules bundle.js:46971
    promise callback*_resolveToken task.ts:211
    _createResumable task.ts:233
    _start task.ts:186
    node_modules bundle.js:46919
    UploadTask task.ts:156
    uploadBytesResumable$1 reference.ts:291
    uploadBytesResumable api.ts:167
    initiateTransaction TimeStampTest.js:12
    React 23
    js index.js:7
    factory react refresh:6
    Webpack3

    TimeStampTest.js:40

​

上传工作正常错误来时,我试图暂停操作,我会很感激,如果有人能告诉我一条出路...

jhkqcmku

jhkqcmku1#

尝试将firebase更新到最新版本:
npm安装防火墙@9.15.0-canary.3ee35f9ae
最近暂停的错误被发现并修复,但还没有在稳定版本中发布。

相关问题