问题
As a contrived example:
- User uploads photo
- 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