一个链接的Firebase存储桶上传失败,但通过相同API和文件类型的其他链接未失败

zc0qhyus  于 2023-02-09  发布在  其他
关注(0)|答案(1)|浏览(138)

我在firebase bucket上传时遇到了一个问题。我的函数通过API获取链接,下载并上传到存储器。API中的所有链接都正常工作,只有一个例外,我不知道为什么会这样,这是一个奇怪的错误,我无法精确定位responseUrl告诉我什么。为什么只有一个失败,而其他的都没有?
这是我从桶中得到的错误

[info] >  GaxiosError: Request failed with status code 400 {"user":"GaxiosError: Request failed with status code 400","metadata":{"emulator":{"name":"functions"},"function":{"name":"us-central1-UploadPodcastToStorage"},"extension":{},"message":"\u001b[90m> \u001b[39m GaxiosError: Request failed with status code 400"}}
[info] >      at Gaxios._request (/Users/bakrredwan/Desktop/Spring 2023/Junior Design/JID-2352-The-Emoroid-Digest-App-Backend/functions/node_modules/gaxios/build/src/gaxios.js:129:23) {"user":"    at Gaxios._request (/Users/bakrredwan/Desktop/Spring 2023/Junior Design/JID-2352-The-Emoroid-Digest-App-Backend/functions/node_modules/gaxios/build/src/gaxios.js:129:23)","metadata":{"emulator":{"name":"functions"},"function":{"name":"us-central1-UploadPodcastToStorage"},"extension":{},"message":"\u001b[90m> \u001b[39m     at Gaxios._request (/Users/bakrredwan/Desktop/Spring 2023/Junior Design/JID-2352-The-Emoroid-Digest-App-Backend/functions/node_modules/gaxios/build/src/gaxios.js:129:23)"}}
[info] >      at runMicrotasks (<anonymous>) {"user":"    at runMicrotasks (<anonymous>)","metadata":{"emulator":{"name":"functions"},"function":{"name":"us-central1-UploadPodcastToStorage"},"extension":{},"message":"\u001b[90m> \u001b[39m     at runMicrotasks (<anonymous>)"}}
[info] >      at processTicksAndRejections (node:internal/process/task_queues:96:5) {"user":"    at processTicksAndRejections (node:internal/process/task_queues:96:5)","metadata":{"emulator":{"name":"functions"},"function":{"name":"us-central1-UploadPodcastToStorage"},"extension":{},"message":"\u001b[90m> \u001b[39m     at processTicksAndRejections (node:internal/process/task_queues:96:5)"}}
[info] >      at async Upload.makeRequest (/Users/bakrredwan/Desktop/Spring 2023/Junior Design/JID-2352-The-Emoroid-Digest-App-Backend/functions/node_modules/@google-cloud/storage/build/src/gcs-resumable-upload.js:598:21) {"user":"    at async Upload.makeRequest (/Users/bakrredwan/Desktop/Spring 2023/Junior Design/JID-2352-The-Emoroid-Digest-App-Backend/functions/node_modules/@google-cloud/storage/build/src/gcs-resumable-upload.js:598:21)","metadata":{"emulator":{"name":"functions"},"function":{"name":"us-central1-UploadPodcastToStorage"},"extension":{},"message":"\u001b[90m> \u001b[39m     at async Upload.makeRequest (/Users/bakrredwan/Desktop/Spring 2023/Junior Design/JID-2352-The-Emoroid-Digest-App-Backend/functions/node_modules/@google-cloud/storage/build/src/gcs-resumable-upload.js:598:21)"}}
[info] >      at async Upload.getAndSetOffset (/Users/bakrredwan/Desktop/Spring 2023/Junior Design/JID-2352-The-Emoroid-Digest-App-Backend/functions/node_modules/@google-cloud/storage/build/src/gcs-resumable-upload.js:547:26) {"user":"    at async Upload.getAndSetOffset (/Users/bakrredwan/Desktop/Spring 2023/Junior Design/JID-2352-The-Emoroid-Digest-App-Backend/functions/node_modules/@google-cloud/storage/build/src/gcs-resumable-upload.js:547:26)","metadata":{"emulator":{"name":"functions"},"function":{"name":"us-central1-UploadPodcastToStorage"},"extension":{},"message":"\u001b[90m> \u001b[39m     at async Upload.getAndSetOffset (/Users/bakrredwan/Desktop/Spring 2023/Junior Design/JID-2352-The-Emoroid-Digest-App-Backend/functions/node_modules/@google-cloud/storage/build/src/gcs-resumable-upload.js:547:26)"}}
[info] >      at async Upload.continueUploading (/Users/bakrredwan/Desktop/Spring 2023/Junior Design/JID-2352-The-Emoroid-Digest-App-Backend/functions/node_modules/@google-cloud/storage/build/src/gcs-resumable-upload.js:341:9) { {"user":"    at async Upload.continueUploading (/Users/bakrredwan/Desktop/Spring 2023/Junior Design/JID-2352-The-Emoroid-Digest-App-Backend/functions/node_modules/@google-cloud/storage/build/src/gcs-resumable-upload.js:341:9) {","metadata":{"emulator":{"name":"functions"},"function":{"name":"us-central1-UploadPodcastToStorage"},"extension":{},"message":"\u001b[90m> \u001b[39m     at async Upload.continueUploading (/Users/bakrredwan/Desktop/Spring 2023/Junior Design/JID-2352-The-Emoroid-Digest-App-Backend/functions/node_modules/@google-cloud/storage/build/src/gcs-resumable-upload.js:341:9) {"}}
[info] >    response: { {"user":"  response: {","metadata":{"emulator":{"name":"functions"},"function":{"name":"us-central1-UploadPodcastToStorage"},"extension":{},"message":"\u001b[90m> \u001b[39m   response: {"}}
[info] >      config: { {"user":"    config: {","metadata":{"emulator":{"name":"functions"},"function":{"name":"us-central1-UploadPodcastToStorage"},"extension":{},"message":"\u001b[90m> \u001b[39m     config: {"}}
[info] >        method: 'PUT', {"user":"      method: 'PUT',","metadata":{"emulator":{"name":"functions"},"function":{"name":"us-central1-UploadPodcastToStorage"},"extension":{},"message":"\u001b[90m> \u001b[39m       method: 'PUT',"}}
[info] >        url: 'http://127.0.0.1:9199/upload/storage/v1/b/the-emoroid-digest-app-882e5.appspot.com/o?name=PodcastMedia%2FDr_Boike_Podcast_Episode_Mix_-_7_21_22_551_PM6fpry.mp3&uploadType=resumable&upload_id=ccd96604-28fb-4131-bd36-9fa7b77c0a16', {"user":"      url: 'http://127.0.0.1:9199/upload/storage/v1/b/the-emoroid-digest-app-882e5.appspot.com/o?name=PodcastMedia%2FDr_Boike_Podcast_Episode_Mix_-_7_21_22_551_PM6fpry.mp3&uploadType=resumable&upload_id=ccd96604-28fb-4131-bd36-9fa7b77c0a16',","metadata":{"emulator":{"name":"functions"},"function":{"name":"us-central1-UploadPodcastToStorage"},"extension":{},"message":"\u001b[90m> \u001b[39m       url: 'http://127.0.0.1:9199/upload/storage/v1/b/the-emoroid-digest-app-882e5.appspot.com/o?name=PodcastMedia%2FDr_Boike_Podcast_Episode_Mix_-_7_21_22_551_PM6fpry.mp3&uploadType=resumable&upload_id=ccd96604-28fb-4131-bd36-9fa7b77c0a16',"}}
[info] >        headers: [Object], {"user":"      headers: [Object],","metadata":{"emulator":{"name":"functions"},"function":{"name":"us-central1-UploadPodcastToStorage"},"extension":{},"message":"\u001b[90m> \u001b[39m       headers: [Object],"}}
[info] >        validateStatus: [Function (anonymous)], {"user":"      validateStatus: [Function (anonymous)],","metadata":{"emulator":{"name":"functions"},"function":{"name":"us-central1-UploadPodcastToStorage"},"extension":{},"message":"\u001b[90m> \u001b[39m       validateStatus: [Function (anonymous)],"}}
[info] >        paramsSerializer: [Function: paramsSerializer], {"user":"      paramsSerializer: [Function: paramsSerializer],","metadata":{"emulator":{"name":"functions"},"function":{"name":"us-central1-UploadPodcastToStorage"},"extension":{},"message":"\u001b[90m> \u001b[39m       paramsSerializer: [Function: paramsSerializer],"}}
[info] >        responseType: 'json' {"user":"      responseType: 'json'","metadata":{"emulator":{"name":"functions"},"function":{"name":"us-central1-UploadPodcastToStorage"},"extension":{},"message":"\u001b[90m> \u001b[39m       responseType: 'json'"}}
[info] >      }, {"user":"    },","metadata":{"emulator":{"name":"functions"},"function":{"name":"us-central1-UploadPodcastToStorage"},"extension":{},"message":"\u001b[90m> \u001b[39m     },"}}
[info] >      data: 'Bad Request', {"user":"    data: 'Bad Request',","metadata":{"emulator":{"name":"functions"},"function":{"name":"us-central1-UploadPodcastToStorage"},"extension":{},"message":"\u001b[90m> \u001b[39m     data: 'Bad Request',"}}
[info] >      headers: { {"user":"    headers: {","metadata":{"emulator":{"name":"functions"},"function":{"name":"us-central1-UploadPodcastToStorage"},"extension":{},"message":"\u001b[90m> \u001b[39m     headers: {"}}
[info] >        'access-control-expose-headers': 'content-type,x-firebase-storage-version,x-goog-upload-url,x-goog-upload-status,x-goog-upload-command,x-gupload-uploadid,x-goog-upload-header-content-length,x-goog-upload-header-content-type,x-goog-upload-protocol,x-goog-upload-status,x-goog-upload-chunk-granularity,x-goog-upload-control-url', {"user":"      'access-control-expose-headers': 'content-type,x-firebase-storage-version,x-goog-upload-url,x-goog-upload-status,x-goog-upload-command,x-gupload-uploadid,x-goog-upload-header-content-length,x-goog-upload-header-content-type,x-goog-upload-protocol,x-goog-upload-status,x-goog-upload-chunk-granularity,x-goog-upload-control-url',","metadata":{"emulator":{"name":"functions"},"function":{"name":"us-central1-UploadPodcastToStorage"},"extension":{},"message":"\u001b[90m> \u001b[39m       'access-control-expose-headers': 'content-type,x-firebase-storage-version,x-goog-upload-url,x-goog-upload-status,x-goog-upload-command,x-gupload-uploadid,x-goog-upload-header-content-length,x-goog-upload-header-content-type,x-goog-upload-protocol,x-goog-upload-status,x-goog-upload-chunk-granularity,x-goog-upload-control-url',"}}
[info] >        connection: 'close', {"user":"      connection: 'close',","metadata":{"emulator":{"name":"functions"},"function":{"name":"us-central1-UploadPodcastToStorage"},"extension":{},"message":"\u001b[90m> \u001b[39m       connection: 'close',"}}
[info] >        'content-length': '11', {"user":"      'content-length': '11',","metadata":{"emulator":{"name":"functions"},"function":{"name":"us-central1-UploadPodcastToStorage"},"extension":{},"message":"\u001b[90m> \u001b[39m       'content-length': '11',"}}
[info] >        'content-type': 'text/plain; charset=utf-8', {"user":"      'content-type': 'text/plain; charset=utf-8',","metadata":{"emulator":{"name":"functions"},"function":{"name":"us-central1-UploadPodcastToStorage"},"extension":{},"message":"\u001b[90m> \u001b[39m       'content-type': 'text/plain; charset=utf-8',"}}
[info] >        date: 'Sat, 28 Jan 2023 21:01:04 GMT', {"user":"      date: 'Sat, 28 Jan 2023 21:01:04 GMT',","metadata":{"emulator":{"name":"functions"},"function":{"name":"us-central1-UploadPodcastToStorage"},"extension":{},"message":"\u001b[90m> \u001b[39m       date: 'Sat, 28 Jan 2023 21:01:04 GMT',"}}
[info] >        etag: 'W/"b-EFiDB1U+dmqzx9Mo2UjcZ1SJPO8"', {"user":"      etag: 'W/\"b-EFiDB1U+dmqzx9Mo2UjcZ1SJPO8\"',","metadata":{"emulator":{"name":"functions"},"function":{"name":"us-central1-UploadPodcastToStorage"},"extension":{},"message":"\u001b[90m> \u001b[39m       etag: 'W/\"b-EFiDB1U+dmqzx9Mo2UjcZ1SJPO8\"',"}}
[info] >        vary: 'Origin', {"user":"      vary: 'Origin',","metadata":{"emulator":{"name":"functions"},"function":{"name":"us-central1-UploadPodcastToStorage"},"extension":{},"message":"\u001b[90m> \u001b[39m       vary: 'Origin',"}}
[info] >        'x-powered-by': 'Express' {"user":"      'x-powered-by': 'Express'","metadata":{"emulator":{"name":"functions"},"function":{"name":"us-central1-UploadPodcastToStorage"},"extension":{},"message":"\u001b[90m> \u001b[39m       'x-powered-by': 'Express'"}}
[info] >      }, {"user":"    },","metadata":{"emulator":{"name":"functions"},"function":{"name":"us-central1-UploadPodcastToStorage"},"extension":{},"message":"\u001b[90m> \u001b[39m     },"}}
[info] >      status: 400, {"user":"    status: 400,","metadata":{"emulator":{"name":"functions"},"function":{"name":"us-central1-UploadPodcastToStorage"},"extension":{},"message":"\u001b[90m> \u001b[39m     status: 400,"}}
[info] >      statusText: 'Bad Request', {"user":"    statusText: 'Bad Request',","metadata":{"emulator":{"name":"functions"},"function":{"name":"us-central1-UploadPodcastToStorage"},"extension":{},"message":"\u001b[90m> \u001b[39m     statusText: 'Bad Request',"}}
[info] >      request: { {"user":"    request: {","metadata":{"emulator":{"name":"functions"},"function":{"name":"us-central1-UploadPodcastToStorage"},"extension":{},"message":"\u001b[90m> \u001b[39m     request: {"}}
[info] >        responseURL: 'http://127.0.0.1:9199/upload/storage/v1/b/the-emoroid-digest-app-882e5.appspot.com/o?name=PodcastMedia%2FDr_Boike_Podcast_Episode_Mix_-_7_21_22_551_PM6fpry.mp3&uploadType=resumable&upload_id=ccd96604-28fb-4131-bd36-9fa7b77c0a16' {"user":"      responseURL: 'http://127.0.0.1:9199/upload/storage/v1/b/the-emoroid-digest-app-882e5.appspot.com/o?name=PodcastMedia%2FDr_Boike_Podcast_Episode_Mix_-_7_21_22_551_PM6fpry.mp3&uploadType=resumable&upload_id=ccd96604-28fb-4131-bd36-9fa7b77c0a16'","metadata":{"emulator":{"name":"functions"},"function":{"name":"us-central1-UploadPodcastToStorage"},"extension":{},"message":"\u001b[90m> \u001b[39m       responseURL: 'http://127.0.0.1:9199/upload/storage/v1/b/the-emoroid-digest-app-882e5.appspot.com/o?name=PodcastMedia%2FDr_Boike_Podcast_Episode_Mix_-_7_21_22_551_PM6fpry.mp3&uploadType=resumable&upload_id=ccd96604-28fb-4131-bd36-9fa7b77c0a16'"}}
[info] >      } {"user":"    }","metadata":{"emulator":{"name":"functions"},"function":{"name":"us-central1-UploadPodcastToStorage"},"extension":{},"message":"\u001b[90m> \u001b[39m     }"}}
[info] >    }, {"user":"  },","metadata":{"emulator":{"name":"functions"},"function":{"name":"us-central1-UploadPodcastToStorage"},"extension":{},"message":"\u001b[90m> \u001b[39m   },"}}
[info] >    config: { {"user":"  config: {","metadata":{"emulator":{"name":"functions"},"function":{"name":"us-central1-UploadPodcastToStorage"},"extension":{},"message":"\u001b[90m> \u001b[39m   config: {"}}
[info] >      method: 'PUT', {"user":"    method: 'PUT',","metadata":{"emulator":{"name":"functions"},"function":{"name":"us-central1-UploadPodcastToStorage"},"extension":{},"message":"\u001b[90m> \u001b[39m     method: 'PUT',"}}
[info] >      url: 'http://127.0.0.1:9199/upload/storage/v1/b/the-emoroid-digest-app-882e5.appspot.com/o?name=PodcastMedia%2FDr_Boike_Podcast_Episode_Mix_-_7_21_22_551_PM6fpry.mp3&uploadType=resumable&upload_id=ccd96604-28fb-4131-bd36-9fa7b77c0a16', {"user":"    url: 'http://127.0.0.1:9199/upload/storage/v1/b/the-emoroid-digest-app-882e5.appspot.com/o?name=PodcastMedia%2FDr_Boike_Podcast_Episode_Mix_-_7_21_22_551_PM6fpry.mp3&uploadType=resumable&upload_id=ccd96604-28fb-4131-bd36-9fa7b77c0a16',","metadata":{"emulator":{"name":"functions"},"function":{"name":"us-central1-UploadPodcastToStorage"},"extension":{},"message":"\u001b[90m> \u001b[39m     url: 'http://127.0.0.1:9199/upload/storage/v1/b/the-emoroid-digest-app-882e5.appspot.com/o?name=PodcastMedia%2FDr_Boike_Podcast_Episode_Mix_-_7_21_22_551_PM6fpry.mp3&uploadType=resumable&upload_id=ccd96604-28fb-4131-bd36-9fa7b77c0a16',"}}
[info] >      headers: { {"user":"    headers: {","metadata":{"emulator":{"name":"functions"},"function":{"name":"us-central1-UploadPodcastToStorage"},"extension":{},"message":"\u001b[90m> \u001b[39m     headers: {"}}
[info] >        'Content-Length': 0, {"user":"      'Content-Length': 0,","metadata":{"emulator":{"name":"functions"},"function":{"name":"us-central1-UploadPodcastToStorage"},"extension":{},"message":"\u001b[90m> \u001b[39m       'Content-Length': 0,"}}
[info] >        'Content-Range': 'bytes */*', {"user":"      'Content-Range': 'bytes */*',","metadata":{"emulator":{"name":"functions"},"function":{"name":"us-central1-UploadPodcastToStorage"},"extension":{},"message":"\u001b[90m> \u001b[39m       'Content-Range': 'bytes */*',"}}
[info] >        'x-goog-api-client': 'gl-node/16.16.0 gccl/5.20.5 gccl-invocation-id/37c940e8-01c8-4cf9-8fc8-64a4436a46bd', {"user":"      'x-goog-api-client': 'gl-node/16.16.0 gccl/5.20.5 gccl-invocation-id/37c940e8-01c8-4cf9-8fc8-64a4436a46bd',","metadata":{"emulator":{"name":"functions"},"function":{"name":"us-central1-UploadPodcastToStorage"},"extension":{},"message":"\u001b[90m> \u001b[39m       'x-goog-api-client': 'gl-node/16.16.0 gccl/5.20.5 gccl-invocation-id/37c940e8-01c8-4cf9-8fc8-64a4436a46bd',"}}
[info] >        Accept: 'application/json' {"user":"      Accept: 'application/json'","metadata":{"emulator":{"name":"functions"},"function":{"name":"us-central1-UploadPodcastToStorage"},"extension":{},"message":"\u001b[90m> \u001b[39m       Accept: 'application/json'"}}
[info] >      }, {"user":"    },","metadata":{"emulator":{"name":"functions"},"function":{"name":"us-central1-UploadPodcastToStorage"},"extension":{},"message":"\u001b[90m> \u001b[39m     },"}}
[info] >      validateStatus: [Function (anonymous)], {"user":"    validateStatus: [Function (anonymous)],","metadata":{"emulator":{"name":"functions"},"function":{"name":"us-central1-UploadPodcastToStorage"},"extension":{},"message":"\u001b[90m> \u001b[39m     validateStatus: [Function (anonymous)],"}}
[info] >      paramsSerializer: [Function: paramsSerializer], {"user":"    paramsSerializer: [Function: paramsSerializer],","metadata":{"emulator":{"name":"functions"},"function":{"name":"us-central1-UploadPodcastToStorage"},"extension":{},"message":"\u001b[90m> \u001b[39m     paramsSerializer: [Function: paramsSerializer],"}}
[info] >      responseType: 'json' {"user":"    responseType: 'json'","metadata":{"emulator":{"name":"functions"},"function":{"name":"us-central1-UploadPodcastToStorage"},"extension":{},"message":"\u001b[90m> \u001b[39m     responseType: 'json'"}}
[info] >    }, {"user":"  },","metadata":{"emulator":{"name":"functions"},"function":{"name":"us-central1-UploadPodcastToStorage"},"extension":{},"message":"\u001b[90m> \u001b[39m   },"}}
[info] >    code: '400' {"user":"  code: '400'","metadata":{"emulator":{"name":"functions"},"function":{"name":"us-central1-UploadPodcastToStorage"},"extension":{},"message":"\u001b[90m> \u001b[39m   code: '400'"}}
[info] >  } {"user":"}","metadata":{"emulator":{"name":"functions"},"function":{"name":"us-central1-UploadPodcastToStorage"},"extension":{},"message":"\u001b[90m> \u001b[39m }"}}

responseURL显示以下内容:

{"error":{"code":404,"message":"No such object: upload/storage/v1/b/the-emoroid-digest-app-882e5.appspot.com/o","errors":[{"message":"No such object: upload/storage/v1/b/the-emoroid-digest-app-882e5.appspot.com/o","domain":"global","reason":"notFound"}]}}

现在的代码看起来就像这样。我已经初始化了bucket并导入了所有正确的firebase函数。我正在等待下载完成,然后继续上传,那么为什么上传找不到目录呢?它对所有其他相同类型的下载都有效。

async function savePodcastFromExternalLinkToStorageHelper(sourceLink: string, saveToFolder: string, docRef: DocumentReference<admin.firestore.DocumentData>) {
  const snap = await docRef.get();
  if (snap.data().media_storage != undefined) {
    return new Promise((resolve, reject) => {
      resolve("Podcast: (" + snap.data().title + ") uploaded or already exists!");
    })
  }
  const tempDir = `/tmp/${saveToFolder}`;
  await download(sourceLink, `${tempDir}/`);
  let filename = fs.readdirSync(`${tempDir}/`).filter((fileName) =>
    fileName.startsWith(sourceLink.substring(sourceLink.lastIndexOf("/") + 1))
  );
  const stroagePath = `${saveToFolder}/${filename[0]}`;
  if (filename.length > 0) {
    try {
      await bucket.upload(`${tempDir}/${filename[0]}`, { destination: stroagePath })
      fs.rmSync(`${tempDir}/${filename[0]}`);
      const podcast = {
        media_storage: stroagePath,
      };
      await docRef.update(podcast);
      return new Promise((resolve, reject) => {
        resolve(snap.data().title + " sucessfully uploaded!")
      })
    }
    catch (error) {
      console.log(error);
      fs.rmSync(`${tempDir}/${filename[0]}`, { force: true });
      return new Promise((resolve, reject) => {
        reject(snap.data().title + " failed to upload")
      })
    }
  } else {
    throw new Error(`Don't know the file name of ${sourceLink}`);
  }
}

只有一个特定的链接失败,而其他本质上是相同文件类型和来自相同API的链接没有失败,这里可能有什么问题?
我试着在调用函数时等待它,但这会停止firebase云函数调用,因为有超时和内存限制,如果有意义的话,我需要在不等待函数的情况下异步调用它。总的来说,这个问题非常奇怪,因为链接确实有效,我可以访问它们。
如果你需要更多的信息,请说,我可以简单地编辑后添加它。道歉,如果我没有张贴足够的。

kcwpcxri

kcwpcxri1#

所以我实际上已经找到了一个解决方案。幸好所有下载的文件类型都是相同的,所以实际上声明内容类型“audio/mp3”成功了。不知道为什么一个单一的上传没有成功,但其他的成功了。也许未来对多个文件类型的修复是基于从元数据提取的标签传递类型声明,所以它永远不会失败。

相关问题