You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Firebase Storage图片上传报错:指定存储桶不存在(桶名已确认正确)

Firebase Storage 上传图片报错:指定存储桶不存在

错误信息

Error: The service storage has thrown an exception. HttpStatusCode is NotFound. The specified bucket does not exist

现有代码

ar storage = StorageClient.Create();
               
string studentImageRef = bucket + 33333 + ".jpg";

var obj = storage.GetObject(studentImageRef, studentImageRef);
var downloadUrl = obj.MediaLink;

await storage.UploadObjectAsync(obj, null, new UploadObjectOptions { PredefinedAcl = PredefinedObjectAcl.PublicRead });

// Add the download URL to the student's information
studentsInfo.ImageUrl = downloadUrl;

问题排查与修复

  • 客户端初始化缺失凭据
    StorageClient.Create()默认无法关联到你的Firebase项目,必须使用Firebase服务账号密钥初始化:

    var credential = GoogleCredential.FromFile("你的服务账号密钥文件路径.json");
    var storage = StorageClient.Create(credential);
    
  • 存储桶格式不正确
    Firebase Storage的桶必须是完整域名格式:[桶名].appspot.com,确认bucket变量是否包含完整后缀,而非仅桶名。

  • 代码逻辑颠倒
    你先调用GetObject获取一个尚未上传的对象,这会直接触发不存在的错误。正确流程是先上传文件,再获取链接:

    // 本地文件路径
    string localImagePath = "本地图片的绝对路径.jpg";
    string objectName = "33333.jpg";
    
    // 执行上传
    var uploadedObject = await storage.UploadObjectAsync(
        bucket, 
        objectName, 
        "image/jpeg", 
        File.OpenRead(localImagePath), 
        new UploadObjectOptions { PredefinedAcl = PredefinedObjectAcl.PublicRead }
    );
    
    // 赋值下载链接
    studentsInfo.ImageUrl = uploadedObject.MediaLink;
    
  • 权限与项目匹配问题
    确认服务账号拥有Firebase Storage的读写权限,且该账号所属的Google Cloud项目与Firebase项目完全一致,可在Google Cloud控制台IAM页面检查权限配置。

内容的提问来源于stack exchange,提问作者Jericho

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.02 12:35:23