简体   繁体   English

通过Nodejs Firebase函数删除文件Google Cloud Storage时出现FetchError

[英]FetchError while deleting files Google Cloud Storage via Nodejs Firebase functions

I am having a fetchError while trying to delete multiple files in a single bucket.我在尝试删除单个存储桶中的多个文件时遇到 fetchError。 My application requires finding older objects and then deleting any files a user has uploaded to the cloud storage.我的应用程序需要查找旧对象,然后删除用户上传到云存储的所有文件。

So when I loop through files to delete, I seem to get a fetchError when there are too many files to delete.因此,当我遍历要删除的文件时,当要删除的文件太多时,我似乎会得到一个 fetchError 。

At first it was working fine(testing phase) but now I notice that I get a fetchError when there is too many files to delete at the same time.起初它工作正常(测试阶段)但现在我注意到当有太多文件要同时删除时我得到一个 fetchError 。

error:错误:

{ FetchError: request to https://storage.googleapis.com/storage/v1/b/bucketName/o/filePath? failed, reason: socket hang up
    at ClientRequest.<anonymous> (/srv/node_modules/node-fetch/lib/index.js:1453:11)
    at emitOne (events.js:116:13)
    at ClientRequest.emit (events.js:211:7)
    at TLSSocket.socketErrorListener (_http_client.js:401:9)
    at emitOne (events.js:116:13)
    at TLSSocket.emit (events.js:211:7)
    at emitErrorNT (internal/streams/destroy.js:66:8)
    at _combinedTickCallback (internal/process/next_tick.js:139:11)
    at process._tickDomainCallback (internal/process/next_tick.js:219:9)
  message: 'request to https://storage.googleapis.com/storage/v1/b/bucketName/o/filePath? failed, reason: socket hang up',
  type: 'system',
  errno: 'ECONNRESET',
  code: 'ECONNRESET' }

my deleteFunction:我的删除功能:

I query a collection, then loop the querysnapshot to get the individual documentsnapshots where I get the image and video filePaths which I pass into deleteFile(myBucketName, mediaFilePath)我查询一个集合,然后循环查询快照以获取各个文档快照,从中获取图像和视频文件路径,并将其传递给deleteFile(myBucketName, mediaFilePath)

const gcs = new Storage();

async function deleteFile(bucketName, fileName) {

 await gcs.bucket(bucketName).file(fileName).delete();

}

I am thinking, should I update the meta-data of the images to be deleted and listen in another function for onMetaDataChange for storage and then delete it?我在想,我是否应该更新要删除的图像的元数据并在另一个 function 中监听 onMetaDataChange 进行存储,然后将其删除? Would that be any better?那会更好吗?

This doesn't seem to be an issue with Storage or Cloud Functions.这似乎不是存储或云功能的问题。 Seems to be an issue with your implementation to handle multiple-requests as the error is related to the socket.由于错误与套接字有关,因此处理多个请求的实现似乎是一个问题。 ( Here's is explained better). 这里解释得更好)。 You can use batch requests or this answer could help you.您可以使用批处理请求,或者这个答案可以帮助您。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我可以通过 Firebase Cloud Functions 压缩 Firebase 存储中的文件吗? - Can I zip files in Firebase Storage via Firebase Cloud Functions? 无法使用Firebase功能删除Google Cloud Storage文件 - Cannot delete Google Cloud Storage files using Firebase Functions 使用Cloud Functions for Firebase和@ google-cloud / storage删除图像时出现问题 - issues deleting an image using Cloud Functions for Firebase and @google-cloud/storage 删除Google Cloud Functions的tmp文件夹中的文件 - Deleting Files in tmp folder of Google Cloud Functions 如何从Google Cloud Functions NodeJS连接到Google云端存储 - How to connect to Google Cloud Storage from Google Cloud Functions NodeJS 使用 Firebase Cloud Functions 将文件上传到 Firebase 存储时出错 - Error while uploading file to Firebase Storage using Firebase Cloud Functions 无法从Node.js上传到Google Cloud或Firebase存储桶 - Can't upload to google cloud or firebase storage bucket from nodejs Google Cloud IOT-通过 Firebase/云功能进行设备配置? - Google Cloud IOT- Device Configuration via Firebase/cloud functions? 通过http下载并使用Node.js流传输到Google Cloud存储 - Download via http and streaming upload to Google Cloud storage using nodejs 使用云功能将多个文件保存到Firebase存储 - Save multiple files to Firebase storage using cloud functions
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM