我将 google.cloud.storage 用于 .mp3 文件。我之前尝试过它并且有效。现在我编写了另一个使用现有存储功能的新功能。一切都应该工作,但我得到这个奇怪的错误:“Google.Apis.Requests.RequestError text-to-speach@XXXXXXXXXXX.iam.gserviceaccount.com 没有 storage.objects.create 访问 objectsound/voiceAnimals20.mp3。[ 403]”我不知道从什么开始。有谁能够帮我?
Ok存储功能在这里:
public static string VoiceStorage(int catId, string URL,
Dictionary<string, int> voicesCounter)
{
Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS",
@"C:\wordproject-XXXXXXXXXX.json");
// upload the image storage
//----------------
string voiceName;
voiceName = "voice" + BLLcategory.GetCategoryById(catId).CategoryName
+ voicesCounter[BLLcategory.GetCategoryById(catId).CategoryName]++ +
".mp3";
string bucketName = "XXXXXXXX";
var storage = StorageClient.Create();
using (var f = File.OpenRead(URL))
{
try
{
var res = storage.UploadObject(bucketName, voiceName, null,
f);
URL = "https://storage.cloud.google.com/" + bucketName + "/" +
voiceName;
}
catch (Exception e)
{
throw e;
}
}
return URL;
}
新的不工作功能是:
private void button12_Click(object sender, EventArgs e)
{
foreach (COMimageObject obj in BLLobject.GetObjects())
{
if(obj.VoiceURL==null)
{
try
{
string url=BLLtextToSpeach.TextToSpeach(obj.Name);
url=BLLtextToSpeach.VoiceStorage(
BLLimage.GetImageById(obj.ImageID).CategoryID,
url, voicesCounter);
BLLobject.UpdateVoiceURL(obj.ObjectId, url);
}
catch (Exception)
{
throw;
}
}
}
}
在 url=BLLtextToSpeach.VoiceStorage tnx 行之后发生的问题!
