I have been battling this one for a while now. I have am using Paperclip and AWS-SDK. I have my bucket and account configured. Permissions are granted. The form data, including the Paperclip model values all save to my Sqlite3 table. However, the image does not upload to my bucket on S3. I receive no errors. Any suggestions on what could be going wrong here?
Thanks in advance.
Here's is the attachment control, which is inside my form. The form routes to the Create method on my Animal controller.
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/
So I figured it out and I figured I should post the solution, so that way I can get more down votes. Even though I have seen countless Paperclip posts on here with similar problems, whom, received multiple up votes.
Removing the credentials from my config/environments/development file and placing all configuration in my model seemed to do the trick. Also, I had a hash symbol in my style field.
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"
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments