![](/img/trans.png)
[英]How do I receive and use a JSON object on the client-side from the server (Node JS and Express)?
[英]How do I upload to Google Cloud Storage from client-side JavaScript, with Node on the server?
我想从我的客户端 JavaScript 代码直接上传到Google Cloud Storage 存储桶,尽管该存储桶不应公开写入。 服务器端代码是 Node.js。 过去,通过为服务器上的客户端生成临时授权,我可以直接上传到 Amazon S3。 将文件上传到受写保护的 Google Cloud Storage 存储桶(即需要授权)的过程是什么?
我发现我可以使用getSignedUrl ,它应该允许对文件进行某些临时访问(例如写入):
bucket = gcs.bucket('aBucket')
bucket.file('aFile').getSignedUrl({
action: 'write',
expires: moment.utc().add(1, 'days').format(),
}, (error, signedUrl) => {
if (error == null) {
console.log(`Signed URL is ${signedUrl}`)
}
})
为了上传文件,向获得的签名 URL 发出 PUT 请求。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.