使用c#插入Google Cloud Storage时将对象设置为Shared Public URL [英] Setting an object to Shared Public URL when inserting into Google Cloud Storage using c#
本文介绍了使用c#插入Google Cloud Storage时将对象设置为Shared Public URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在将MP3文件上传到Google云端存储中的存储桶,但想使插入的文件公开可用,并获取其URL.
I am uploading an MP3 file to a bucket in google cloud storage, but would like to make the inserted file publicly available and grab the url for it.
下面是我当前的代码,但是我无法弄清楚如何在对象上传后设置其权限以使其公开可用.
Below is my current code, but i cannot figure how to set the permission on the object after it is uploaded to make it publicly available.
Google.Apis.Storage.v1.Data.Object fileobj = new Google.Apis.Storage.v1.Data.Object() { Name = "recording.mp3" };
Console.WriteLine("Creating " + fileobj.Name + " in bucket " + bucketName);
byte[] file = File.ReadAllBytes(@"C:\Users\test\Desktop\stream\recording.mp3");
using (MemoryStream memory = new MemoryStream(file))
{
using (BinaryReader reader = new BinaryReader(memory))
{
for (int i = 0; i < file.Length; i++)
{
byte result = reader.ReadByte();
Console.WriteLine(result);
}
}
}
using (var streamOut = new MemoryStream(file))
{
await service.Objects.Insert(fileobj, bucketName, streamOut, "audio/mpeg3").UploadAsync();
}
推荐答案
添加到fileobj:
Add to fileobj:
Acl = new List<ObjectAccessControl>
{
new ObjectAccessControl
{
Role = "OWNER",
Entity = "allUsers"
}
}
这篇关于使用c#插入Google Cloud Storage时将对象设置为Shared Public URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文