【问题标题】:File upload to Google Cloud Storage with SignedUrl使用 SignedUrl 将文件上传到 Google Cloud Storage
【发布时间】:2018-10-31 06:40:32
【问题描述】:

我正在尝试上传图片。我已将我的signedUrl 放入我的存储桶,但我无法发出正确的http put 请求。我正在使用超级代理库。

const req = superagent.put(url)
  .attach(file.name, file)
  .end();

文件对象是https://developer.mozilla.org/en-US/docs/Web/API/File 结束 url 是来自我的服务器的 signedUrl。 没有附件我可以上传一个空文件。但是通过附件我得到一个 http 403 错误。如何使用此signedUrl 上传文件?

【问题讨论】:

  • 403 代码是服务器理解调用,但一些授权失败。您如何生成要传递给请求的签名 URL?

标签: javascript node.js google-cloud-storage superagent


【解决方案1】:

我遇到了同样的问题,因为我的请求中缺少 Content-Type 标头。尝试像这样添加它:

const req = superagent.put(url)
  .attach(file.name, file)
  .set('Content-Type', file.type);
  .end();

希望对你有帮助!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-12-23
    • 1970-01-01
    • 2017-04-02
    • 2019-11-07
    • 2023-03-13
    • 1970-01-01
    • 2020-04-04
    相关资源
    最近更新 更多