问题描述
我正在尝试在vue js中构建图像上传器,并且希望它可以恢复上传,并且我正在将请求从浏览器直接发送到云存储服务器(例如,不使用php作为发送上传请求的中间件)
i am trying to build image uploader in vue js and i want it to be resumable upload and i am sending the request directly to cloud storage server from browser (not using php for example as a middle-ware to send upload request )
但是文档说我必须具有访问令牌才能获取会话URL,稍后将使用该URL上传图像.如何使用JavaScript获取此访问令牌,Google Cloud没有用于javascript的库,但是在节点js中,我可以
but the docs says i must have access token to get session url which i will use later to upload image , How To get this access token using JavaScript , google cloud doesn't have library for javascript but in node js which i can't use for browser usage
POST https://www.googleapis. com/upload/storage/v1/b/myBucket/o?uploadType = resumable HTTP/1.1授权:不记名[YOUR_AUTH_TOKEN]
POST https://www.googleapis.com/upload/storage/v1/b/myBucket/o?uploadType=resumable HTTP/1.1Authorization: Bearer [YOUR_AUTH_TOKEN]
在此页面上: https://cloud .google.com/storage/docs/json_api/v1/how-tos/resumable-upload
推荐答案
您绝对不希望通过将自己的访问令牌传递给客户端来做到这一点.访问令牌允许持有者在其范围内做任何事情,直到它们过期.拥有您的访问令牌的恶意用户可能会导致几乎无限的问题.
You definitely do NOT want to do that by passing your own access token to the client. Access tokens allow the holder to do anything within their scope until they expire. A malicious user who has your access token could cause almost unlimited problems.
您要么需要让客户使用他们自己的Google凭据(不常见,但是对于管理其他人的Google Cloud资源的第三方工具才有意义),或者使用某种形式的签名URL或类似功能.
You'll either need to have your customers use their own Google credentials (unusual, but makes sense for a third party tool for managing someone else's Google Cloud resources) or use some form of signed URL or similar feature.
这篇关于云存储可恢复上传访问令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!