【发布时间】:2014-11-05 17:45:24
【问题描述】:
我正在尝试在使用 jQuery 和 Rails 上传到 s3 目录时设置文件的内容类型。我已经成功实现Ryan Bate's solution 没有问题。
问题是内容类型未设置,默认为binary/octet-stream。我在 Ryan 的解决方案中添加了以下内容:
uploader_helper.rb
def fields
{
# ...
:content_type => nil,
# ...
}
end
paintings.js.coffee
$("#fileupload").fileupload
add: (e, data) ->
# ...
if types.test(file.type) || types.test(file.name)
# ...
data.form.find('#content_type').attr('name','Content-Type')
data.form.find('#content_type').val(file.type)
data.submit()
# ...
此外,我的 CORS 配置如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>http://localhost:3000</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<AllowedMethod>POST</AllowedMethod>
<AllowedMethod>PUT</AllowedMethod>
<MaxAgeSeconds>3000</MaxAgeSeconds>
<AllowedHeader>*</AllowedHeader>
</CORSRule>
</CORSConfiguration>
我在尝试添加这些字段时收到403 (Forbidden) 错误。
我尝试添加存储桶策略,但没有帮助。
【问题讨论】:
标签: ruby-on-rails amazon-s3 jquery-file-upload