在 s3 上上传 froala 图像

upload froala images on s3

我在我的应用程序中使用 react-froala-wysiwyg 编辑器。但我无法在 s3 存储桶上上传图片。当我尝试在 s3 上上传图片时; s3 returns 禁止错误:403.

任何人都可以分享在 s3 上为 reactjs 上传图像的配置。

以下是我的配置。

var config = {

  imageUploadToS3: {
    bucket: 'testing-s3upload',
    // Your bucket region.
    region: 'us-east-1',
    keyStart: 'froalaUploads/',
    params: {
      acl: 'public-read',
      AWSAccessKeyId: 'xxxxxxxxx',
      AWSSecretAccessKey: 'xxxxxxxxxxxxxxxxxxxx',
      policy: '', // i have no policy applied on my bucket.
      signature: '',
    }
  }
}

Asper the froala 编辑器文档:

In order to get the image uploaded to S3, it is necessary to compute a signature using the AWS access key ID and AWS secret access key and provide it together with the upload request. The rich text editor Ruby SDK comes with methods to compute the S3 signature using the V4 signing algorithm that works with buckets created on any of the S3 regions.

他们还提供了样本:

class UploadController < ActionController::Base

  ...

  def index
    # Configuration object.
    options = {
      # The name of your bucket.
      bucket: 'bucket-name',

      # S3 region. If you are using the default us-east-1, it this can be ignored.
      region: 'eu-west-1',

      # The folder where to upload the images.
      keyStart: 'uploads',

      # File access.
      acl: 'public-read',

      # AWS keys.
      accessKey: 'YOUR_AWS_ACCESS_KEY',
      secretKey: 'YOUR_AWS_SECRET_KEY'
    }

    # Compute the signature.
    @aws_data = FroalaEditorSDK::S3.data_hash(options)
  end

  ...

end

你的情况是你没有创建签名,这一定是错误。

Official Link