我尝试使用 npm 包 "npm:/@google-cloud/storage"通过 Deno 将文件上传到 Google Cloud Storage
,但由于两者之间不兼容,我收到错误Deno 和 Node 模块:错误:未实现:crypto.Sign
有人知道使用 Deno 将文件上传到 Google Cloud Storage 的替代方法吗?
最佳答案
您可以使用 Google Cloud REST API:https://cloud.google.com/storage/docs/uploading-objects?hl=en#rest-upload-objects
const token = 'OAUTH TOKEN'
const bucket = 'BUCKET_NAME'
const file = await Deno.readFile('./sample.txt');
const res = await fetch(`https://storage.googleapis.com/upload/storage/v1/b/${bucket}/o?uploadType=media&name=sample.txt`, {
headers: {
'Content-Type': 'text/plain',
Authorization: `Bearer ${token}`
},
method: 'POST',
body: file
})
const data = await res.json();
要获取 token ,您可以使用 OAuth 2.0 Playground然后使用那里获得的刷新 token 刷新 token
关于google-cloud-storage - 使用 Deno 将文件上传到 Google 存储,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75606650/