我正在将一个MP3文件上传到谷歌云存储中的一个存储桶,但是想要将插入的文件公之于众,并获取它的网址。
以下是我当前的代码,但我无法确定如何在上传对象后设置对象的权限以使其公开可用。
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();
}
答案 0 :(得分:1)
添加到fileobj:
Acl = new List<ObjectAccessControl>
{
new ObjectAccessControl
{
Role = "OWNER",
Entity = "allUsers"
}
}