google-cloud-storage - 使用 Deno 将文件上传到 Google 存储

标签 google-cloud-storage deno

我尝试使用 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/

相关文章:

django - 对于 django-storages 和 GCE,如何设置 GS_CREDENTIALS?

google-cloud-storage - gsutil 复制到存储失败

node.js - 在heroku上获取对node.js中主目录的写访问权限以解决ResumableUploadError

google-cloud-storage - Google Cloud Storage 'static' 存储桶名称不可用

使用 Deno 或 Rust 的 MongoDB Schema

typescript - Deno REPL 无法识别 TypeScript 变量声明

versioning - 如何在 Deno 中保留包的版本

javascript - 如何在 Deno 中将 arrayBuffer 转换为 Uint8Array?

java - 在应用程序引擎中上传图像和使用 getServingUrl() 的正确流程是什么?

typescript - 如何在 Deno 中提取类型