简体   繁体   English

使用nodejs从谷歌云存储下载多个文件失败,没有错误

[英]Downloading multiple files from Google cloud storage using nodejs fails without errors

My code successfully downloads some of the files but not all.我的代码成功下载了一些文件,但不是全部。 Execution just stops in the middle without any errors and the last file may be only partially downloaded.执行只是在中间停止,没有任何错误,最后一个文件可能只下载了部分。 It always fails to download some files even if I change the number of files or if I use different files.即使我更改文件数量或使用不同的文件,它总是无法下载某些文件。 File size doesn't seem to matter.文件大小似乎并不重要。

I've tried many things but it seems that I'm not able to catch any exceptions or errors when it stops.我已经尝试了很多东西,但似乎在它停止时我无法捕捉到任何异常或错误。 I've tried using try-catch and process.on events but not able to catch anything.我试过使用 try-catch 和 process.on 事件,但无法捕捉到任何东西。

I'm pretty sure few months ago I used this kind of code to download hundreds of files without any problems.我很确定几个月前我使用这种代码下载了数百个文件而没有任何问题。

Here is a simplified version of my current code.这是我当前代码的简化版本。

const { Storage } = require('@google-cloud/storage');
const storage = new Storage({ keyFilename: 'D:/myProject/myKeyFile.json' });

var folder = 'D:/myProject/downloadedFiles';
var bucketName = 'bucket_1';

async function downloadFile(fileName) {
  var fullPath = folder + '/' + fileName;
  const options = {
    destination: fullPath,
  };
  await storage.bucket(bucketName).file(fileName).download(options);
  console.log(`gs://${bucketName}/${fileName} downloaded to ${fullPath}.`);
}

async function downloadFiles() {
  var filenames = ['file1', 'file2', 'file3', 'file4', 'file5', 'file6'];

  for(var i = 0; i < filenames.length; i++){
    await downloadFile(filenames[i], i).catch(console.error);
  }
}
downloadFiles().catch(console.error);

It turns out the download only fails on that specific computer, so my code is not the problem.事实证明下载仅在那台特定计算机上失败,所以我的代码不是问题所在。 My guess it is.network related, maybe because a.network switch was replaced some time ago.我猜这是与.network 相关的,可能是因为前段时间更换了.network 交换机。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM