Everything is fine, except URL of image it adds GET request to the of link
"/system/users/images/000/000/074/original/e742caf8bdfb1536e39060eb9d10a4ab.jpeg**?2015**"
Because of this, image is not available(even I open it by direct link), if I delete ?2015, everything works good. Why gem is adding to the end of link get request?
I used default :path, :url(in public/system folder)
and this one
:path => ":rails_root/app/assets/images/article_images/:id/:style_:basename.:extension"
:url => "/app/assets/images/article_images/:id/:style_:basename.:extension"
The problem is in both of ways((
Just add :use_timestamp => false to your paperclip configuration.
Related
I have an API that generate png files.
The user request the generation, and I reply with a path to the generated files.
This is how I generate the URL:
url_for(:controller => :anaction, :action => :download, :path => "#{#relative_dir}/face", :format => 'png'
This yeild an URL that looks like:
http://0.0.0.0:3000/anaction/aging/download/%2FTMP_20161128204315_346482_695%2Fface.png
That should be handled by
def download
send_file "#{Rails.public_path}/#{params[:path]}.#{params[:format]}"
end
According to my route
get '/anaction/aging/download/:path' => 'mpsynthesizer_aging#download'
It works like a charm on my dev environment, on my nginx server, but fail on my apache server.
I get a plain apache HTTP400 error, it seems that the request is never forwarded to rails.
I use rails 4.2.6
Is there something i misunderstood ?
I ended up using
render body: IO.binread(result_file), content_type: "image/png"
Using Paperclip to attach avatars to User profiles for my rails application. I followed the instructions on the paperclip github to initialize and attach to my app.
I have an image in the public/images/medium/missing.png and for both cases (when I upload or when I fallback on the default) I get no image. I've checked my directory and there is an image where it says it is looking but does not grab it. Additionally when I have tried uploading images, I know the image is uploaded correctly because when calling the User in rails console shows all the information properly attached.
I am calling the image in my view like:
<%= image_tag(#blog.user.avatar.url(":medium"), :class => "image-circle avatar") %>
my Paperclip declaration in the User model looks like the following:
has_attached_file :avatar, :styles => { :medium => "300x300>", :thumb => "100x100#"}, :default_url => "/public/images/:style/missing.png"
validates_attachment_content_type :avatar, :content_type => /\Aimage\/.*\Z/
Really not sure what is going on. The route errors that appear when I inspect the improperly loaded image point directly to the image in my local server. And the fact that it can't grab either the missing or the uploaded file also has me at a loss. Any help would be super appreciated!!
And for good measure the output when I examine a user with an uploaded avatar:
avatar_file_name: "11390219_10206114805925816_6595348111261743639_n.j...", avatar_content_type: "image/jpeg", avatar_file_size: 101926, avatar_updated_at: "2015-07-10 18:51:44">
Thanks in advance!
EDIT
This is the URL that is providing the 404 error:
http://localhost:3000/images/medium/missing.png
while in my local directory it goes "root/public/images/medium/missing.png"
not sure how its not grabbing it, unless I am just missing something really obvious somewhere. (i tried hard routing the public in there as well, but to no avail).
EDIT
There is the possibility that you're simply not serving the static assets, add:
config.serve_static_assets = true
to your development.rb
ORIGINAL POST
In you application.rb ( or an environment specific file ), you should have a config.paperclip_defaults = { ... }, here is the link in the docs: https://github.com/thoughtbot/paperclip#defaults
Here is an example one, using fog:
config.paperclip_defaults = {
:storage => :fog,
:fog_credentials => {
:provider => "Local",
:local_root => "#{Rails.root}/public"
},
:fog_directory => "",
:fog_host => "localhost:3000"
}
Do you have something like that in your application? I just tested on an app of mine, and I was able to upload an image, but not to see any without the paperclip_defaults hash. Also, don't forget to restart your app after you update the config files. I hope this helps!
Have you tried killing the quotes around the image style? Around :medium?
<%= image_tag(#blog.user.avatar.url(:medium), :class => "image-circle avatar") %>
As show here in the Paperclip Docs:
https://github.com/thoughtbot/paperclip#show-view
Same problem, solved it by reinstalling imagemagic with brew
Details: In case you're imagemagic, try to update the imagemagic and if it asks you to link it,
Try with this:
brew link --overwrite imagemagick
It worked for me. Hope its helpful
I'm tying to get a cloudfront distribution wired up with a custom domain to paperclip but it's not generating my url properly. Here is my configuration:
# initializers/paperclip_defaults.rb
Paperclip::Attachment.default_options.merge!({
:storage => :s3,
:s3_credentials => "#{Rails.root}/config/amazon_s3.yml",
:bucket => "my-image-bucket",
:path => "production/attachments/:attachment/:id/:style/:basename.:extension",
:url => ":s3_host_alias",
:s3_headers => {'Cache-Control' => 'max-age=2147483648'},
:s3_protocol => :https,
:s3_host_alias => "cdn.mydomain.com",
})
According to the docs and every blog post I've read this should be correct. The problem is that it winds up generating this:
https://s3.amazonaws.com/my-image-bucket/production/products/images/44/original/my-image.jpg
The only way I've gotten it to use the CNAME is by specifying s3_host_name which according to the documentation is only used for the Tokyo region. And this also breaks uploads. Any ideas as to what I'm doing wrong?
I'm using Paperclip 3.5.2.
UPDATE
I'm debugging inside attachment.rb#url and here's what I'm seeing. Paperclip::Attachment.default_options[:url] returns cdn.mydomain.com which is correct. However, #options[:url] is returning :s3_path_url instead of s3_host_alias. For some reason that default option is not being merged in properly. However the s3_host_alias option is since #options[:s3_host_alias] is returning cdn.mydomain.com as expected.
So it turns out that :s3_alias_url is the correct token to use for the url and not :s3_host_alias. Not sure where that's documented though. Had to look at s3.rb to figure it out.
I have a RoR app that is using paperclip for upload images, and the color-box gem to view a larger version of the image. The problem is that it woks fine in development, but when I try to take the app to production it is looking for the image in the wrong place.
It tries to find the image in the root directory and gives an error that the file does not exist at URL/system/pictures/2/large/img.png, when it should be looking for the image in URL/s12/gallery/bsd/system/pictures/2/large/img.png
I don't know how to tell the app to look for the file in URL/s12/gallery/bsd/ Any help would be appreciated, let me know if more info is needed.
Here is how I am linking to the file in the view:
<%= link_to(image_tag(#project.picture.url(:thumb)), #project.picture.url(:large), :data=> { :colorbox => true }) %>
That gets the thumbnail to show up fine, but when clicked it says there is no file in the root directory...because there isn't.
Thank you.
has_attached_file :photo, :styles => { :small => "150x150>" },
:url => "/assets/products/:id/:style/:basename.:extension",
:path => ":rails_root/public/assets/products/:id/:style/:basename.:extension"
you can set the url to change the defaults. also path is the system path where url is the url for the public
Keep getting a broken pipe after uploading a mp3 with paperclip to S3. What did i do wrong?
Model
has_attached_file :mp3,
:storage => :s3,
:path => 'mp3/:class/:id/:style.:extension',
:s3_credentials => "#{RAILS_ROOT}/config/s3.yml",
:bucket => 'cobras-production',
:url => ':s3_domain_url'
Controller
def create
#track = Track.new(params[:track])
if #track.save
redirect_to(#track, :notice => 'Track was successfully created.')
else
render :action => "new"
end
end
I think there may be an issue with non us bucket locations.
I have 2 applications set up to run on heroku, and was running into the issue you mention. When i changed my bucket location to US the paperclip lib worked perfectly with exact same file.
Where you using singapore or tokyo as your bucket locaiton.
https://github.com/marcel/aws-s3/issues/#issue/4
this explains the issue better
In my case it was because I chose a new (as of now) AWS region 'Oregon'.
When I switched back to US Standard for my bucket, I had no problems.
It might be worth pointing out that buckets are not created automatically on-demand - you have to create them yourself. If you're using the aws-s3 gem, the command for that is
AWS::S3::Bucket.create("cobras-production")
For future googlers: I had the same issue, the reason was in wrong time on my computer, which was included in request. Amazon's server compared my time and their, which caused an error.