简体   繁体   English

使用 Google App Engine 将大文件上传到 Google Cloud Storage

[英]Upload large files to Google Cloud Storage using Google App Engine

I would like to upload files up to 1GB to Google Cloud Storage.我想将最大 1GB 的文件上传到 Google Cloud Storage。 I'm using Google App Engine Flexible.我正在使用 Google App Engine 灵活。 From what I understand, GAE has a 32MB limit on file uploads, which means I have to either upload directly to GCS or break the file into chunks.据我了解,GAE 对文件上传有 32MB 的限制,这意味着我必须直接上传到 GCS 或将文件分成块。

This answer from several years ago suggests using the Blobstore API, however there doesn't seem to be an option for Node.js and the documentation also recommends using GCS instead of Blobstore to store files.几年前的这个答案建议使用 Blobstore API,但是 Node.js 似乎没有选项,并且文档还建议使用 GCS 而不是 Blobstore 来存储文件。

After doing some searching, it seems like using signed urls to upload directly to GCS may be the best option, but I'm having trouble finding any example code on how to do this.在进行了一些搜索之后,似乎使用签名的 url 直接上传到 GCS 可能是最好的选择,但我无法找到有关如何执行此操作的任何示例代码。 Is this the best way and are there any examples of how to do this using App Engine with Node.js?这是最好的方法吗?是否有任何示例说明如何将 App Engine 与 Node.js 结合使用?

Your best bet would be to use the Cloud Storage client library for Node.js to create a resumable upload .最好的办法是使用适用于 Node.js 的 Cloud Storage 客户端库来创建可恢复的上传

Here's the official code example on how to create the session URI:以下是有关如何创建会话 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];
});

Edit: It seems you can nowadays use the createWriteStream method to perform an uplaod without having to worry about creation of a URL.编辑:现在您似乎可以使用createWriteStream方法来执行上传,而不必担心创建 URL。

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

相关问题 Google云端:存储和App Engine - Google Cloud: Storage and App Engine 保护Google Cloud App Engine(NodeJS)中的文件 - Securing files in Google Cloud app engine (NodeJS) APP Engine Google Cloud Storage - 下载文件时出现错误 500 - APP Engine Google Cloud Storage - Error 500 when downloading a file 从 Google Cloud Function 将大文件上传到 Google Cloud Storage 失败 - Failed large file upload to Google Cloud Storage from Google Cloud Function 使用Node.js将大量文件上传到Google存储桶 - Upload large amount of files to Google Storage bucket with Node.js 异步上传多个文件到谷歌云存储桶 - async upload multiple files to google cloud storage bucket 如何在 Google Cloud Function 的 /tmp 文件夹中下载文件,然后将其上传到 Google Cloud Storage - How to download files in /tmp folder of Google Cloud Function and then upload it in Google Cloud Storage 重命名谷歌云存储中的文件? - renaming files in Google Cloud Storage? 通过http下载并使用Node.js流传输到Google Cloud存储 - Download via http and streaming upload to Google Cloud storage using nodejs 如何使用nodejs将内存文件数据上传到谷歌云存储? - How to upload an in memory file data to google cloud storage using nodejs?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM