通过CloudFront上传文件时出错

时间:2017-09-09 17:22:26

标签: amazon-web-services amazon-cloudfront fine-uploader

通过CloudFront将文件上传到AWS S3存储桶时,我收到以下错误

不支持您提供的授权机制。请使用AWS4-HMAC-SHA256

同样上传,但直接到S3工作。我正在使用react-fine-uploader和JAVA后端。我可以看到后端正在使用V4。可能是什么原因? 在java后端我有:

 if (req.getQueryString() != null && req.getQueryString().contains("v4=true")) {
            System.out.println("Signing with the V4 signature");
            handleV4SignatureRequest(jsonObject, contentJson, req, resp);
        } else {
            System.out.println("Signing with the V2 signature");
            handleV2SignatureRequest(jsonObject, contentJson, req, resp);
        }

SOP显示"使用V4签名"

进行签名

我的配置:

 uploader = new FineUploaderS3({
    options: {
      debug: true,
      deleteFile: {
        enabled: true,
        endpoint: `${config.environment.api_baseUrl}/s3`,
        customHeaders: {
          'Authorization': 'Basic ' + btoa(config.WS_USERNAME + ':' + config.WS_PASSWORD)
        }
      },
      request: {
        endpoint: `${config.AWS_S3_END_POINT}`,
        accessKey: `${config.AWS_S3_ACCESS_KEY}`
      },
      signature: {
        endpoint: `${config.environment.api_baseUrl}/s3/signature`,
        version: 4,
        customHeaders: {
          'Authorization': 'Basic ' + btoa(config.WS_USERNAME + ':' + config.WS_PASSWORD),
        }
      },
      uploadSuccess: {
        endpoint: `${config.environment.api_baseUrl}/s3/success`,
        customHeaders: {
          'Authorization': 'Basic ' + btoa(config.WS_USERNAME + ':' + config.WS_PASSWORD)
        }
      },
      validation: {
        sizeLimit: 5000000,
        itemLimit: 10
      },
      callbacks: {
        onComplete: (id, fileName, responseJSON) => {
          const { submittedFiles } = this.state;
          let newFile = {
            name: responseJSON.name,
            s3Bucket: responseJSON.s3Bucket,
            s3Key: responseJSON.s3Key,
            size: this.uploader.methods.getSize(id),
            uuid: responseJSON.uuid
          }

          submittedFiles.push(newFile);
          this.setState({ submittedFiles });
        },
        onDeleteComplete: (id) => {
          const { submittedFiles } = this.state;
          let newUuid = this.uploader.methods.getUuid(id);
          let removeElement = arrayObjectIndexOf(submittedFiles, newUuid, 'uuid');

          submittedFiles.splice(removeElement, 1);
          this.setState({ submittedFiles });
        }
      },
      messages: {
        tooManyItemsError: 'You can only add 10 files'
      },
      chunking: {
        enabled: true
      },
      objectProperties: {
        region: `${config.AWS_S3_REGION}`
      }
    }
  })

0 个答案:

没有答案