I would like to upload an image from iOS to S3.The production environment is in Heroku, and I would like to save only the images in S3.The development is done by Rails, and the library uses paperclip.I referred to the link, but the error "status code:500, headers" returned. https://devcenter.heroku.com/articles/paperclip-s3
We haven't been able to identify the problem yet.If you have any advice, please let me know.
#terminal
$heroku config:set S3_BUCKET_NAME="kenja.jp"
$heroku config:set AWS_ACCESS_KEY_ID=my_access_key_id
$heroku config:set AWS_SECRET_ACCESS_KEY=my_secret_access_key
# app/models/user.rb
has_attached_file: photo,
:styles=>{medium:"300x300>", thumb:"100x100>";",
:storage=>:s3,
: bucket=>'kenja.jp',
—s3_permissions=>:public,
:url=>":s3_domain_url",
:path=>"/assets/photos/:id/:style/:basename.:extension",
:s3_host_name=>"s3-ap-northeast-1.amazonaws.com",
:s3_credentials=>: "#{Rails.root}/config/s3.yml"
# config / environments / staging.rb
config.paperclip_defaults={
:storage=>:s3,
:s3_credentials=>{
: bucket=>ENV ['kenja.jp'],
—access_key_id=>ENV['my_access_key_id',
—secret_access_key=>ENV ['my_secret_access_key']
}
}
#config/paperclip.rb
Paperclip::Attachment.default_options[:url]=':s3_domain_url'
Paperclip::Attachment.default_options[:path]='/:class/:attachment/:id/:style.:extension'
Paperclip::Attachment.default_options [:s3_host_name] = 's3-ap-northeast-1.amazonaws.com'
# app/apis/v1/users.rb
params do
requirements:id, type: Integer
requirements:icon, type:Rack::Multipart::UploadedFile
end
post'/post_picture'do
photo_file=ActionDispatch::Http::UploadedFile.new (params[:icon])
@user=User.find (params[:id])
@user.update(photo:photo_file)
@user.photo
end
Since it is 500 errors, I think there is some kind of error on the server side (Rails side).
If you look at the Heroku server log, you should see detailed error messages and stack traces.Please confirm that first.
A careful review of the error messages and stack traces may solve this problem by itself.
If resolved, answer the cause and solution yourself.
If not, please add the log and what you have tried to resolve.
I checked herokurogs and found the following error:
2015-10-18T06:33:10.144859 + 00:00 app [web.1]:app/apis/v1/users.rb:112:in `block(2 levels) in<class:Users>'
2015-10-18T06:33:10.144858 + 00:00 app [web.1]: NameError (uninitialized constant paperclip::Storage::S3::AWS):
2015-10-18T06:33:10.128265 + 00:00 app [web.1]: User Load (0.9ms) SELECT "users".* FROM "users" WHERE" users"."id" = $1 LIMIT1 [[["id", 15]]
When I checked the link, it seems that I should have done the following.
gem 'aws-sdk', '<2.0'
https://stackoverflow.com/questions/28374401/nameerror-uninitialized-constant-paperclipstorages3aws
© 2024 OneMinuteCode. All rights reserved.