firebase - 使用 HTTP REST api 在颤振中使用 FIREBASE STORAGE 时出错
问题描述
将图像文件插入 Firebase Stroage 时出现错误。我正在使用 HTTP rest api 来做同样的事情。
代码如下:
Future<void> upload(Image image2) async {
var accountCredentials = ServiceAccountCredentials.fromJson({
"private_key_id": " ",
"private_key": " ",
"client_email":"< >.iam.gserviceaccount.com",
"client_id": "",
"type": "service_account"
});
var scopes = [
'https://www.googleapis.com/auth/cloud-platform',
];
var client = Client();
AccessCredentials credentials =
await obtainAccessCredentialsViaServiceAccount(accountCredentials, scopes, client);
String accessToken = credentials.accessToken.data;
var request = Request(
'POST',
Uri.parse(
'https://www.googleapis.com/upload/storage/v1/b/mybucket/o?uploadType=media&name=$image2'),
);
request.headers['Authorization'] = "Bearer $accessToken";
request.headers['Content-Type'] = "image/png";
Response response = await Response.fromStream(await request.send());
print("response is ");
print(response.statusCode);
print("response body");
print(response.body);
client.close();
}
错误如下:
{
"error": {
"code": 403,
"message": "< >.iam.gserviceaccount.com does not have storage.objects.create access
to the Google Cloud Storage object.",
"errors": [
{
"message": "< >.gserviceaccount.com does not have storage.objects.create access to the
Google Cloud Storage object.",
"domain": "global",
"reason": "forbidden"
}
]
}
}
我已通过 IAM 服务管理授予 storage.objects.create 的权限,但这不起作用
解决方案
推荐阅读
- html - CSS动画没有正确填充垂直高度?
- r - 使用 ggplot2 将其他系列添加到面板/平面图
- linux - Windows 等效于应用程序范围的 Linux 钱包
- python - 蛇游戏中更新列表的问题
- r - 用 str_replace 条件替换
- python - 每次我运行/部署应用程序时,Heroku postgres DB 都会丢弃更改
- wordpress - 暂时无法进行定期维护。请过一会再回来查看。没有 .maintenance 文件
- python - S3 预签名 URL 在创建存储桶后 90 分钟有效
- nginx - 如何手动在服务器上重新加载 gunicorn?
- reactjs - 根据用户对 react-table 的选择动态显示/隐藏列:React+Typescript