我在这个主题上看到了很多问题,但是我遇到的任何问题对我都有用,所以我在这里发布另一个......
我正在Ruby on Rails上尝试使用jQuery File Upload插件直接配置文件上传到Amazon S3 .我跟着非常有用的Heroku教程来完成初始设置.文件上传很好,但是它们都标记为Content-Type: binary/octet-streamS3,所以当它们在应用程序中提供时,所有文件都会下载而不是直接打开.
这是一个问题,因为我试图允许图像,PDF,音频或视频文件,所以我需要能够Content-Type从文件中获取正确的文件并将其传递给S3.在看在亚马逊AWS的-SDK文档宝石,我看到这一节有关添加.where(:content_type).starts_with("")到presigned后对象的末尾修改政策.但是,当我这样做时,它引发了一个错误:
<Error><Code>AccessDenied</Code>
<Message>Invalid according to Policy: Policy Condition failed: ["starts-with", "$Content-Type", ""]</Message>
Run Code Online (Sandbox Code Playgroud)
所以我添加content_type: ""了预先签名的post对象的opts哈希,现在它再次工作,但是所有文件默认为binary/octet-stream默认的所有文件默认为image/jpeg.这是我现在的代码:
调节器
def new
@s3_direct_post = S3_BUCKET.presigned_post(
key: "uploads/#{SecureRandom.uuid}/${filename}",
success_action_status: 201,
acl: :public_read,
content_type: "").where(:content_type).starts_with("")
end
Run Code Online (Sandbox Code Playgroud)
_form.html.haml
:javascript
$(function() {
$('.directUpload').find("input:file").each(function(i, elem) {
var fileInput = $(elem);
var form = $(fileInput.parents('form:first'));
var submitButton = form.find('input[type="submit"]');
var progressBar = $("<div class='bar'></div>"); …Run Code Online (Sandbox Code Playgroud) jquery content-type ruby-on-rails amazon-s3 jquery-file-upload
我在github上的activeadmin问题板上提出了同样的问题:https: //github.com/gregbell/active_admin/issues/645
嗨,
我有两个不同的问题.
1:我喜欢主动管理员处理has_many与简单DSL的关系,如下所示:
ActiveAdmin.register Artist do
form do |f|
f.inputs do
f.input :name
f.input :description
end
f.inputs "ArtistLinks" do
f.has_many :artist_links do |j|
j.inputs :title, :url
end
end
f.buttons
end
end
Run Code Online (Sandbox Code Playgroud)
在表单底部添加更多链接的能力非常强.
但是,我一直在使用wyiswyg,我似乎无法以这种格式工作.我一直在使用/添加部分像这样:
ActiveAdmin.register NewsItem do
form :partial => "/news_items/form"
end
Run Code Online (Sandbox Code Playgroud)
<%= javascript_include_tag "/javascripts/ckeditor/ckeditor.js" %>
<%= semantic_form_for [:admin, @news_item], :multipart => true do |f| %>
<%= f.inputs :title, :photo, :excerpt %>
<%= cktext_area_tag("news_item[content]", @news_item.content) %>
<%= f.submit %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
但是,在我的部分中,我似乎无法像这样很好地建立has_many关系:
f.inputs "ArtistLinks" do …Run Code Online (Sandbox Code Playgroud)