node.js - 在反应中使用流的谷歌存储文件上传问题
问题描述
每个人。我将从反应前端上传图像,图像文件作为缓冲区发送。在后端,代码如下所示。
const { Storage } = require("@google-cloud/storage");
const path = require("path");
const send = require("../../send.js");
const serviceKey = path.join(__dirname, "./keys.json");
const storage = new Storage({
keyFilename: serviceKey,
projectId: "myprojectID",
});
const bucket = storage.bucket("bucketName");
const uploadImage = async (buffer) => {
const file = bucket.file("newImage.png");
await file.save(buffer);
await file.makePublic();
const publicUrl = `http://storage.googleapis.com/${bucket.name}/${file.name}`;
return publicUrl;
};
看起来文件正在正确上传到谷歌存储桶,但是当这段代码运行时,我收到了这个警告
*!已请求 Google API!
- 网址:“https://www.googleapis.com/oauth2/v4/token”
- 请注意,这可能是生产服务。
!已请求 Google API! - 网址:“https://storage.googleapis.com/upload/storage/v1/b/{“myprojectID”}/o?name=newImage.png&uploadType=resumable”
- 请注意,这可能是生产服务。!已请求 Google API!
- 网址:“https://storage.googleapis.com/upload/storage/v1/b/{“myprojectID”}/o?name=newImage.png&uploadType=resumable&upload_id=ABg5-UxkB7bSW4GOIbaxItWSb94SlAqLsQNK5Zec0v_yN0fYs-1r65jjBSF-yBLlt3VJs3Duhz-uEEAWWFy!” 已请求 Google API!
- 网址:“https://storage.googleapis.com/storage/v1/b/{“myprojectID”}/o/newImage.png/acl?”
存储的大小相同,但是当我单击存储上的该链接时,图像未显示,如果我单击“https://storage.googleapis.com/storage/v1/b/{“myprojectID” }/o/newImage.png/acl?” 它在浏览器上显示此 401 错误。
{
"error": {
"code": 401,
"message": "Anonymous caller does not have storage.objects.getIamPolicy access to the Google Cloud Storage object.",
"errors": [
{
"message": "Anonymous caller does not have storage.objects.getIamPolicy access to the Google Cloud Storage object.",
"domain": "global",
"reason": "required",
"locationType": "header",
"location": "Authorization"
}
]
}
}
谁能帮我?提前致谢。
解决方案
推荐阅读
- java - Java: My while loop is crashing after the Switch case is done
- apache-spark - 是否可以限制分配给 Spark 会话的资源?
- php - 如何在工资报告中插入月份和年份
- azure-ad-b2c - 首次登录时强制重置密码的自定义策略不起作用
- node.js - 在 redux 中获取 JWT 令牌
- sql - 如何在 Shell 脚本中比较两个 SQL 文件
- hibernate - JPA Criteria API selectCase in where 子句
- dataframe - 获取 DataFrame 的 Column 值导致 'Column' 对象不可调用
- php - 缓存存储 [] 未定义
- python - Bigtable python客户端:如何检索大于给定值的最小行键