I am uploading images to S3 storage using paperclip gem. It uploads successfully.
In my application, an user can change his profile photo. If user do the profile photo change, the new image will get uploaded successfully. The problem is the browser will show previous photo only after the upload. Only after a force refresh by the hitting ctrl + F5 will the new image display.
Note: image is uploaded using form post. I guess it's related with caching but I don't have clue where I can change my code. Please help me this out. Thanks.
What property of your image object are you using as the src of your image? If you use user.image.url (assuming that you have a User model and that the Paperclip field's called image) then the URL to the image on S3 should have a number in the querystring that acts to stop any caching so that you see the updated image immediately. For example the URL for the image should change from
http://s3.amazonaws.com/bucket/images/5/original/pic.gif?1250184309
to
http://s3.amazonaws.com/bucket/images/5/original/pic.gif?1250184348
which should stop the browser caching the image.
Related
im new in ruby, here u can find my code: https://bitbucket.org/Messeir/reddit
I used carrierwave gem for uploading photos. Unfortunatelly i dont know how to show uploaded photo on main site near to submited links?
Here are a few thoughts.
The photo is uploaded. We're assuming that it'll land on the file system of your server somewhere.
After you receive the file upload, as a prototype, try to move the file in the Rails root "public/images" directory. On your page, you could try an image tag as such:
If that works, you can tell at least that your "file-upload-save-to-disk" operation is working.
In a second phase, save the file somewhere else, say in a /data/images directory. Create a controller that will respond to a /mycontroller/myimage?... url, an in that method, respond with the image content.
That's pretty rough but it's a start. Let me know how it goes.
I have a rails app, in which i store some images in AWS, and show them in a PDF report. When there is no images to be shown, i show a placeholder, like this one here: .
The problem is: the image is not show in the PDF file. When in debug mode, the image is shown as usual, but never in my PDF! The link to the image is like this: https://dl.dropboxusercontent.com/u/4096865/missing.png
Edit 1:
I tried to include the image like this: image_tag("https://dl.dropboxusercontent.com/u/4096865/missing.png")
The solution i've found was simple, but prevented me from using dropbox for storage: it must be a http url. So, when i uploaded it to AWS S3, it worked!
So, this here works perfectly: image_tag("http://s3-sa-east-1.amazonaws.com/base-fisc-prod/missing.png")
This is an issue with images stored in a HTTPS link, the easiest way to solve this is to store the images in a HTTP link.
If you must store them in HTTPS, use this solution provided here
Basically I fallowed this documentation: tinymce rails image upload
It works, but the problem is that It saves every image in the db before the actual post is created. Thus even if the post isn't finished or saved, the images still remain on the server. And that is just waisting space on the server.
Does anyone know a better way for image upload with tinymce ?
With carrierwave, I'd like to change the image without changing the location(filename). This way, all links to the old image will still work, but point to the new picture.
For example, I upload an image 'promotion1.png'. I link to this image in an editor. Afterwards, I have a new promotion (promotion2.png), and want to update the image without having to go to the editor again. So old filename points to the new file.
How can this be done? I don't want to be forced to use the same filename. I = an unwitting client :)
I'm using carrierwave to upload an image, this works fine up to now.
What i want to do is show the preview of the file to be submitted on the form after having selected the image.
At the moment the code I have is showing the previous image.
<%= image_tag(#book.cover_url(:thumb)) if #book.cover_url %>
how do I show the selected image rather than the image already uploaded?
You don't.
And that has nothing to do with Carrierwave but rather with the fact that the image is not yet sent to the server by your browser so no part of the Rails stack is coming into play here.
What you need is a way to access the image inside the <input type="file"> and display it to the user.
This is possible by using the FileAPI that is part of HTML5, but it's only supported in modern browsers (Webkit/Gecko), and the API is not completely finished yet so it's kind of a changing target.
I would suggest you look into tools like plupload to upload the image to the server without submitting the form and then displaying that through JavaScript.
Try http://jasny.github.io/bootstrap/javascript/#fileinput
It has a nice solution for displaying the image without the upload.