如何使用 s3 api 和 node.js 将文件上传到 Wasabi 存储桶?

How to upload file into Wasabi bucket with s3 api with node.js?

我在 Amazon s3 存储桶中实现了上传文件,如下所示,它工作正常:


  const S3 = require('aws-sdk/clients/s3');
  const AWS = require('aws-sdk');

  const accessKeyId = 'AKIAYVXDX*******';
  const secretAccessKey = 'gxZpdSDnOfpM*****************';

  const s3 = new S3({
    region: 'us-east-1',
    accessKeyId,
    secretAccessKey
  });

  s3.putObject({
      Body: 'Hello World',
      Bucket: "dev-amazon",
      Key: 'hello.txt'
    }
    , (err, data) => {
      if (err) {
         console.log(err);
      }
    });

并且我需要在Wasabi bucket中实现上传文件。

我试过如下:


  const S3 = require('aws-sdk/clients/s3');
  const AWS = require('aws-sdk');
  const wasabiEndpoint = new AWS.Endpoint('s3.wasabisys.com');

  const accessKeyId = 'PEIL4DYOY*******';
  const secretAccessKey = 'D4jIz3tjJw*****************';

  const s3 = new S3({
    endpoint: wasabiEndpoint,
    region: 'us-east-2',
    accessKeyId,
    secretAccessKey
  });

  s3.putObject({
      Body: 'Hello World',
      Bucket: "dev-wasabi",
      Key: 'hello.txt'
    }
    , (err, data) => {
      if (err) {
         console.log(err);
      }
    });

而 `console.log(err) 的结果是:

err {"message":"The request signature we calculated does not match the signature you provided. Check your key and signing method.","code":"SignatureDoesNotMatch","region":null,"time":"2019-10-30T09:39:19.072Z","requestId":null,"statusCode":403,"retryable":false,"retryDelay":64.72166771381391}

devtools 中的控制台错误:

PUT https://dev-wasabi.s3.us-east-2.wasabisys.com/5efa9b286821fab7df3ece8dc3d6687ed32 403 (Forbidden)

我的代码有什么问题?

我自己找到了这个问题的原因。

wasabiEndpoint 错了。 应该是

  const wasabiEndpoint = new AWS.Endpoint('s3.us-east-2.wasabisys.com ');

根据docs,服务 URL 应该因地区而异。

Wasabi US East 1 (N. Virginia): s3.wasabisys.com or s3.us-east-1.wasabisys.com

Wasabi US East 2 (N. Virginia): s3.us-east-2.wasabisys.com

Wasabi US West 1 (Oregon): s3.us-west-1.wasabisys.com

Wasabi EU Central 1 (Amsterdam): s3.eu-central-1.wasabisys.com

如果这对某人有帮助,我将不胜感激。 :)