I am using paperclip and AWS for my Rails app to upload image. You can find it here: http://lit-stream-6263.herokuapp.com/
When I try to upload images, I don't get an error but for some reason the image doesn't show. When I go into the S3 bucket though, I'm able to see the image that gets uploaded...it's just not rendering in the html page. Any advice on how to fix this?
Update
From 9nonnatus, I'm seeing the picture if I change the URL. However in my rails view I have
<%= image_tag product.avatar.url(:medium) %>
to display the image. This is what I see in the documentation as well. How do I adjust this to fit the url you mention above?
class Product < ActiveRecord::Base
attr_accessible :blog_link, :blog_name, :description, :image_link, :name, :num_likes, :product_link, :avatar
has_attached_file :avatar, :styles => { :medium => "300x300>", :thumb => "100x100>" }, :default_url => "/images/:style/missing.png"
end
Looking at the source of the page you can copy the image link and try to access it in your browser. It gives an error telling you that your hyperlinks are incorrectly formatted. Instead of making the img src format something like:
http://s3.amazonaws.com/rockywolfugc/products/avatars/000/000/003/medium/59577_10100258833612183_1508749_n.jpg?1386876682
you have to use this format:
http://rockywolfugc.s3-us-west-2.amazonaws.com/products/avatars/000/000/003/medium/59577_10100258833612183_1508749_n.jpg?1386876682
In other words, remove /rockywolfugc from after .com and replace s3 with rockywolfugc.s3-us-west-2
Hope that helps.
Related
I've installed imagemagick, paperclip, no prob with the migration and else.. but it shows that my image is broken named Missing, also tried to troubleshoot by copy a tutorial on youtube and other forums, but still, the same problem appeared.. only a post with a broken image.
here is the output I get:
Nahhh the problem is in the post.rb (models).. I change this :
has_attached_file :image, styles: { medium: "300x300>", thumb: "100x100>" }
to this :
has_attached_file :image
i don't know why the styles is the problem.. i thought it will resize the uploaded image.. the image appear but the size is random.. so i put this at views:
<%= image_tag #post.image.url,size:"400x400" %>
Problem solved
I use paperclip to upload a users avatar. The image is stored correctly in the /public directory. However I cant figure out how I can get the image displayed. I played with the :url and :path settings for about an hour and cant match them in a way the image will be displayed in the browser.
There is always a 'images/localhost' in the GET-requests path that I can not get rid of.
Here is my code:
user.rb
class User < ActiveRecord::Base
has_attached_file :avatar, :styles => { :medium => "300x300>", :thumb => "100x100>" }, :default_url => "missing.png",
:url => ':class/:id/:style.:extension',
:path => ':url'
validates_attachment_content_type :avatar, :content_type => /\Aimage\/.*\Z/
end
The path in the html-tag looked up by the request looks like this:
<img alt="Original" src="/images/localhost/users/1/original.png?1405249849" />
The correct request which returns the image would be
http://localhost:3000/users/1/original.png?1405248482.
How can I get the request match the correct file-system-path. Or: what is wrong with my settings?
I didnt change the application.rb or the development.rb
Best regards,
Kev
you should take url or path helpers of paperclip wherever possible. So to show the image use:
<%= image_tag #user.avatar.url(:medium) %>
Then:
the image url isn't a file system path. Depending on the storage you use in paperclip, images can reside in different places, see understanding storage of the paperclip gem.
If you use file storage, the files are store somewhere like
public/system/users/avatar/000/000/013/small/my_pic.png
Timestamp
What you're seeing is Paperclip's timestamp - the last time the file / object was updated.
Although I can't find any official reference to this number, it basically allows you to determine which files you're dealing with. According to the question referenced above, it's apparently there for if you want to ensure your visitors see the latest version of the file (IE never gets stored in the cache)
I'm not sure why there is a disparity between your stored image & your path. However, I would say the path is correct; you just need to be able to
--
Bottom line - if your image shows on the page, I don't think there's any systemic issue with your path; if it doesn't show on the page, can you provide logs / reference to the error?
This post, https://stackoverflow.com/a/26222093/1949363, which pointed to http://www.bwigg.com/2009/10/paperclip-customizing-paths-and-urls/ was the answer for me. I was having issues only in my test environment but I believe the fix should work in other environments as well.
Try the following settings:
:path => "public/system/:class/:id/:filename",
:url => "/system/:class/:id/:basename.:extension"
I am working on a site where I want to be able to display a default image for a user profile if they have not yet uploaded their own image.
I can place the default image in the asset/images directory, but I am wondering how I should make the logic work with image_tag to be able to display the user's image in the view if they've uploaded one or display the default placeholder image in the view if the user has not uploaded one.
I am new to rails, but I would guess that I should put the logic somewhere in my user model and conditionally set the image attribute for the user? I am using Paperclip as well.
The paperclip gem supports a default_url option that is a path to an image that will be rendered if the user has no image. From the paperclip README:
class User < ActiveRecord::Base
attr_accessible :avatar
has_attached_file :avatar, :styles => { :thumb => "100x100>" }, :default_url => "/images/:style/missing.png"
end
So if you call user.avatar.url(:thumb) and it is missing, paperclip will try to render /images/thumb/missing.png. If you create your default missing images and line them up with the default_url parameter, you should be able to let paperclip handle the rest.
I set in an initializer the save-path of paperclip to a new one and everything is fine.
But some attachment-names (like file) are very abstract:
has_attached_file :file, :styles => {
:thumb => "100x100"
}
I want this one within the new save-path, but in a different folder than 'file'. Is that possible, without changing the attachment_name?
For example: Now I'm have something like /save-path/file/thumb, but I want /save-path/my-new-file-name/thumb.
You can manipulate both path and url of the attachment(s) with the Paperclip interpolations. See https://github.com/thoughtbot/paperclip/wiki/interpolations for further reference.
Can anyone tell me the way to zoom the image in Ruby on rails please ?
There's railscast #182 on image Cropping.
If you are using Paperclip, you may specify different sizes for thumbnails, like this:
class Client < ActiveRecord::Base
LOGO_STYLES = {
:original => ['1024x768>', :jpg],
:big => ['512x384#', :jpg],
:medium => ['256x192#', :jpg],
:small => ['128x96#', :jpg]
}
has_attached_file :logo, :styles => Client::LOGO_STYLES
attr_protected :logo_file_name, :logo_content_type, :logo_size
Finally, if you already have the image with the size you want, and you only want to change how it looks on the client, then your problem isn't ruby - it is javascript. Google for "javascript zoom" instead of "rails zoom" :)
You should be clearer.
If what you want to do is allow the user to zoom on an image then you should take a look at javascript.
For example jqzoom, which does a zoom on an image when your mouse is on it.
If what you want is to resize the image to a specific size then it's a ruby/rails problem.
And you can use paperclip to do so.
In your model, you'd add the following :
has_attached_file :my_image, :styles => { :thumb => ["32x32#", :png] }
Where the "32x32" will be the size of the image after it's been resized.
Then you follow the paperclip's README to see the migration and informations to add to the view.
And when you'll validate your form, the image will be automatically uploaded and resized.
If you don't wish to upload the files before to resize them, you can use Paperclip::Thumbnail directly.
And resize your image with the following :
Paperclip::Thumbnail.new('/path/to/your/file', { :geometry => '32x32#' }).make
And you'll have your thumbnail.