我想将最大 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/