这是我当前的代码:

async newCollectionRequest({ commit }, data) {
  try {
    console.log(data);
    const location = `/pending-images/${data.collectionName}/${data.image.name}`;
    console.log(location);

    const storage = getStorage();
    const storageRef = ref(storage, location);

    // 'file' comes from the Blob or File API
    await uploadBytes(storageRef, data.image);
    console.log('Uploaded a blob or file!');
    return true;
  } catch (error) {
    throw error.message;
  }
},

它似乎起作用了,但只是因为我在try 上传图像时收到了403响应.我不确定为什么我一开始就得到了403,因为我已经在应用程序上实现了身份验证,并且我已经确认用户在try 执行此操作时是登录的.这是我的 firebase 基地规则:

rules_version = '2';

service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write: if request.auth != null;
    }
  }
}

我不确定这为什么会导致403错误

推荐答案

您已经发布了一个firestore.rules号文件.您正在使用Firebase存储.您必须在Firebase项目的根目录(与firestore.rules文件所在的位置相同)中创建storage.rules文件,并添加类似以下内容的内容:

rules_version = '2';
service firebase.storage {
  match /b/{bucket}/o {
    match /{allPaths=**} {
      allow read, write: if request.auth != null;
    }
  }
}

这将向任何经过身份验证的用户授予完全读/写访问权限.你可以拿read more about storage rules here美元.

Javascript相关问答推荐

我应该如何在此Angular 16应用程序中的方法中使用@ Hostspel?

使用JavaScript/PHP将二维码保存为服务器端的图像

为什么我会获取MUI Date TimePicker TypHelp:Value.isValid不是AdapterDayjs.isValid中的函数

功能和普通对象之间的原型污染

在JavaScript中打开和关闭弹出窗口

我的glb文件没有加载到我的three.js文件中

D3多线图显示1线而不是3线

确定MutationRecord中removedNodes的索引

如何为GrapesJS模板编辑器创建自定义撤销/重复按钮?

Snowflake JavaScript存储过程返回成功,尽管预期失败

为什么ngModel不能在最后一个版本的Angular 17上工作?'

如何将Cookie从服务器发送到用户浏览器

Angular 中的类型错误上不存在获取属性

JS:XML insertBefore插入元素

在数组中查找重叠对象并仅返回那些重叠对象

在Reaction中的handleSubmit按钮内,useSelector值仍然为空

未加载css colored颜色 ,无法将div设置为可见和不可见

将数组扩展到对象中

如何限制显示在分页中的可见页面的数量

如何为仅有数据可用的点显示X轴标签?