Google Storage set file permission when Save File or Write Stream
The brackets in the Google cloud storage or Firebase storage have a permission set which is common to all files.
However, we should have the capability to set the permission to each file as we need.
Although I have discussed early in the post Make Storage Public , the custom permission can correctly assign using ALC.
Refer the Doc:https://cloud.google.com/nodejs/docs/reference/storage/1.3.x/Acl#add
If you are using a storage file you can access the file and do the modification.
const file = firebase.storage().bucket().file('originals/file.png');
const options = {
entity: 'allUsers',
role: storage.acl.READER_ROLE
};
file.acl.add(options, function(err, aclObject) {});
If you are using a write stream, the process is a bit different.
You have to create metadata variable as below.
const metadata = {
contentType: contentType,
public:true,
'acl': [
{
"entity": "allUsers",
"role": gcloud.acl.READER_ROLE
}
]
};
And set it to the write stream associated with the bucket.
const thumbnailUploadStream = bucket.file(thumbFilePath).createWriteStream({metadata});
However, we should have the capability to set the permission to each file as we need.
Although I have discussed early in the post Make Storage Public , the custom permission can correctly assign using ALC.
Refer the Doc:https://cloud.google.com/nodejs/docs/reference/storage/1.3.x/Acl#add
If you are using a storage file you can access the file and do the modification.
const file = firebase.storage().bucket().file('originals/file.png');
const options = {
entity: 'allUsers',
role: storage.acl.READER_ROLE
};
file.acl.add(options, function(err, aclObject) {});
If you are using a write stream, the process is a bit different.
You have to create metadata variable as below.
const metadata = {
contentType: contentType,
public:true,
'acl': [
{
"entity": "allUsers",
"role": gcloud.acl.READER_ROLE
}
]
};
And set it to the write stream associated with the bucket.
const thumbnailUploadStream = bucket.file(thumbFilePath).createWriteStream({metadata});
Comments
Post a Comment