使用fineuploader和Shrine直接上传到S3

时间:2017-09-26 09:33:05

标签: ruby-on-rails amazon-s3 fine-uploader shrine

我正在尝试一起使用Shrine和fineuploader将我的文件直接上传到S3。

我面临的问题是Shrine gem的presign_endpoint是一个GET请求,它返回一个格式如下的json响应:

{
  "url": "https://my-bucket.s3-eu-west-1.amazonaws.com",
  "fields": {
    "key": "b7d575850ba61b44c8a9ff889dfdb14d88cdc25f8dd121004c8",
    "policy": "eyJleHBpcmF0aW9uIjoiMjAxNS0QwMToxMToyOVoiLCJjb25kaXRpb25zIjpbeyJidWNrZXQiOiJzaHJpbmUtdGVzdGluZyJ9LHsia2V5IjoiYjdkNTc1ODUwYmE2MWI0NGU3Y2M4YTliZmY4OGU5ZGZkYjE2NTQ0ZDk4OGNkYzI1ZjhkZDEyMTAwNGM4In0seyJ4LWFtei1jcmVkZW50aWFsIjoiQUtJQUlKRjU1VE1aWlk0NVVUNlEvMjAxNTEwMjQvZXUtd2VzdC0xL3MzL2F3czRfcmVxdWVzdCJ9LHsieC1hbXotYWxnb3JpdGhtIjoiQVdTNC1ITUFDLVNIQTI1NiJ9LHsieC1hbXotZGF0ZSI6IjIwMTUxMDI0VDAwMTEyOVoifV19",
    "x-amz-credential": "AKIAIJF55TMZYT6Q/20151024/eu-west-1/s3/aws4_request",
    "x-amz-algorithm": "AWS4-HMAC-SHA256",
    "x-amz-date": "20151024T001129Z",
    "x-amz-signature": "c1eb634f83f96b69bd675f535b3ff15ae184b102fcba51e4db5f4959b4ae26f4"
  },
  "headers": {}
}

Fineuploader使用签名端点执行POST请求,因此返回“不允许的方法”错误。

var uploader = new qq.s3.FineUploader({
    request: {
        endpoint: '{ CDN_ENDPOINT_URL }'
        accessKey: '{ ACCESS_KEY }'
    },
    objectProperties: {
        bucket: '{ BUCKET_NAME }'
        host: '{ BUCKET_HOST_NAME }'
    },
    signature: {
        endpoint: '/presign'
    }
});

有没有办法将fineuploader的签名方法更改为GET方法,还是我完全朝错误的方向?欢迎任何有关创建此功能的建议。

我想做一些与https://github.com/gorails-screencasts/shrine-direct-upload-to-s3/blob/master/app/assets/javascripts/uploads.js类似的事情,但需要使用精细上传器。

0 个答案:

没有答案