从应用程序(IOS或android)将图像上传到Google云存储

时间:2018-07-14 10:33:05

标签: node.js google-cloud-platform google-cloud-storage

我正在使用本机反应,并想将图像上传到gcp存储 我没有使用任何应用程序引擎。 根据节点的gcp文档

const Storage = require('@google-cloud/storage');
const storage = Storage({
  projectId: 'id',
  keyFilename: 'private-key'
});

const bucketName = 'buckt';

// Uploads a local file to the bucket
storage
  .bucket(bucketName)
  .upload('filename')
  .then(() => {
    console.log(`${filename} uploaded to ${bucketName}.`);
  })
  .catch(err => {
    console.error('ERROR:', err);
  });

要在客户端中使用此代码,我需要传递不需要的私钥

根据此博客帖子https://medium.com/google-cloud/uploading-resizing-and-serving-images-with-google-cloud-platform-ca9631a2c556,谷歌应用引擎中有一个get_serving_url()函数。

我认为Google推送通知是Google提供的每个客户端令牌,以便客​​户端直接与服务器通信

有什么方法可以直接从客户端上传图像?

1 个答案:

答案 0 :(得分:0)

您可以使用Firabase Cloud Storage服务。此服务可根据Firebase Auth凭据从客户端安全地上传到GCP存储。参见:https://firebase.google.com/docs/storage/