[英]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.