node.js - 使用 Google App Engine 将大文件上传到 Google Cloud Storage

标签 node.js google-cloud-storage google-appengine-node

我想将最大 1GB 的文件上传到 Google Cloud Storage。我正在使用 Google App Engine 灵活。据我了解,GAE 对文件上传有 32MB 的限制,这意味着我必须直接上传到 GCS 或将文件分成块。

answer几年前建议使用 Blobstore API,但是 Node.js 似乎没有选项,文档还建议使用 GCS 而不是 Blobstore 来存储文件。

在进行了一些搜索之后,似乎使用签名的 url 直接上传到 GCS 可能是最好的选择,但我无法找到有关如何执行此操作的任何示例代码。这是最好的方法吗?是否有任何示例说明如何将 App Engine 与 Node.js 结合使用?

最佳答案

最好的办法是使用适用于 Node.js 的 Cloud Storage 客户端库来创建 resumable upload .
这是official关于如何创建 session URI 的代码示例:

const {Storage} = require('@google-cloud/storage');
const storage = new Storage();
const myBucket = storage.bucket('my-bucket');

const file = myBucket.file('my-file');
file.createResumableUpload(function(err, uri) {
  if (!err) {
    // `uri` can be used to PUT data to.
  }
});

//-
// If the callback is omitted, we'll return a Promise.
//-
file.createResumableUpload().then(function(data) {
  const uri = data[0];
});
编辑:现在看来您可以使用 createWriteStream方法来执行上传而不必担心创建 URL。

关于node.js - 使用 Google App Engine 将大文件上传到 Google Cloud Storage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59286380/

相关文章:

python - 使用 Google Storage Bucket 下载速度缓慢

javascript - Express - POST 和 PUT 的 400 错误请求

node.js - 命名空间 'NodeJS' 没有导出成员 'Timeout'

java - Spring:如何从 JAR 加载 "File"资源

谷歌存储文件下载

node.js - GCP 应用引擎 : Random pending requests for static assets (css/images)

debugging - Google App Engine部署调试 "Error Response: [4] Timed out waiting for the app infrastructure to become healthy"

google-app-engine - AppEngine - 节点云任务处理程序的超时时间是多少?

mysql - 我想自动检测环境并设置适当的变量

node.js - Azure 中使用 Node.js 的长时间运行间隔