Is there any supported way for a firebase service accounts to write to your cloud storage buckets?

僤鯓⒐⒋嵵緔 提交于 2019-12-13 07:09:09

问题


As a contrived example:

  1. User uploads photo
  2. Server transforms that photo into thumbnail, medium, high definition and writes the files to the users directory.

Similar to this API but for the server module:


回答1:


Since Firebase Storage is backed by Google Cloud Storage, we recommend using Google Cloud Storage through gcloud-node for this:

// Import gcloud
var gcloud = require('gcloud');

// Initialize with a service account
var gcs = gcloud.storage({
  projectId: 'my-project',
  keyFilename: '/path/to/keyfile.json'
});

// Reference an existing bucket.
var bucket = gcs.bucket('<projectid>.appspot.com');

// Upload a local file to a new file to be created in your bucket.
bucket.upload('/photos/zoo/zebra.jpg', function(err, file) {
  if (!err) {
    // "zebra.jpg" is now in your bucket.
  }
});

// Download a file from your bucket.
bucket.file('giraffe.jpg').download({
  destination: '/photos/zoo/giraffe.jpg'
}, function(err) {});

There are other gcloud modules for Python, Java, go, ruby, etc. here.



来源:https://stackoverflow.com/questions/38521949/is-there-any-supported-way-for-a-firebase-service-accounts-to-write-to-your-clou

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!