我一直在和这个人争斗一段时间。我使用的是Paperclip和AWS-SDK。我配置了我的存储桶和帐户。权限被授予。表单数据,包括Paperclip模型值,全部保存到我的Sqlite3表中。但是,图像不会在S3上传到我的存储桶。我没有收到任何错误。关于这里可能出现什么问题的任何建议?
提前致谢。
这是附件控件,它位于我的表单中。表单路由到Animal控制器上的Create方法。
Paperclip.options[:command_path] = "/usr/local/bin/"
config.paperclip_defaults = {
:storage => :s3,
:bucket => ENV["my bucket"],
:s3_credentials => {
:access_key_id => ENV["My ID"],
:secret_access_key => ["My Secret"]
}
}
Paperclip::Attachment.default_options[:url] = ':s3_domain_url'
Paperclip::Attachment.default_options[:path] = '/:class/:attachment/:id_partition/:style/:filename'
<div class="form-group padding-top-bottom-10">
<%= f.file_field :animal_image %>
<label class="label label-warning">Attach Your Photo</label>
<div class="row padding-top-bottom-10"></div>
</div>
def create
@animal = Animal.new(animal_params)
respond_to do |format|
if @animal.save
flash[:notice] = "#{@animal.full_name} has been added to your profile."
format.json { render json: @animal, status: :created, location: @animal }
format.html { render "animal/index" }
else
flash.now[:error] = @animal.errors.full_messages
format.html { render action: "new" }
format.json { render json: @animal.errors, status: :unprocessable_entity }
end
end
end
private
def animal_params
params.require(:animal).permit(:full_name, :profile_id, :age, :gender, :purr_factor, :weight, :height,
:length, :fixed, :shots, :papers, :animal_desc, :breed_id, :animal_image)
end
:animal_image_content_type
:animal_image_file_name
has_attached_file :animal_image, style: {
thumb: '100x100>',
square: '200x200#',
medium: '300x300>'
}
# Validate the attached image is image/jpg, image/png, etc
validates_attachment_content_type :animal_image, :content_type => /\Aimage\/.*\Z/
答案 0 :(得分:1)
所以我想通了,我想我应该发布解决方案,这样我就可以获得更多的选票。虽然我在这里看到了无数的Paperclip帖子,但也有类似的问题,他们获得了多次投票。
从我的config / environments / development文件中删除凭据并将所有配置放在我的模型中似乎可以解决问题。另外,我的样式字段中有一个哈希符号。
has_attached_file :animal_image,
:style => {:medium => "300x300>", :thumb => "100x100>"},
:storage => :s3,
:bucket => "my bucket",
:s3_credentials => {
:bucket => "my bucket",
:access_key_id => ENV["My key"],
:secret_access_key => ENV["My Secret"]
},
:s3_permissions => "private",
:url => ":s3_domain_url"
Paperclip::Attachment.default_options[:url] = ":s3_domain_url"
Paperclip::Attachment.default_options[:path] = "/:class/:attachment/:id_partition/:style/:filename"