Heroku rails s3 switching end point url - ruby-on-rails

I'm able to save photos, but when I use image_tag, I get this url.
http://s3.amazonaws.com/{bucket}/users/avatars/000/000/001/thumb/{pic}.png?1372135035
when what I want is
http://{bucket}/s3.amazonaws.com/users/avatars/000/000/001/thumb/{pic}.png?1372135035
This seems like it should be simple to solve, but I haven't found it yet.
Thanks

Check this link out, hope this will help you.
Errno::ENOENT (No such file or directory) in amazon-s3

You should try this
#{bucket}/s3.amazonaws.com/users/avatars/000/000/001/thumb/#{pic}.png?1372135035

Related

Upload and download of files using PaperClip

I have a question that I do not really not how to answer ..
I would like my users to be able to upload and download midi files from the website.
For the upload no problem I used paperClip gem. My issue is for the download link I dont know how to do it ...
I tried a few things but the results give me just an url type ..
Could you help me ?
Thx you so much for your help!
Raphael
Solution is as simple as trying this:
<%= link_to #midi.middiz.filename, #midi.middiz.url %>
It will create an anchor tag pointing to the file to be downloaded.

Carrierwave/fog are uploading files to S3, but the app is still trying to use the local path to access images

I know this is a broad question, and I'm biting off a little more than I can chew for a first stab at a rails app, but here I am.
I tried to add an image upload/crop to a basic status app. It was working just fine uploading the images and cropping them with carrierwave, but as soon as I started using Fog to upload to S3, I ran into issues.
The image, and it's different sizes, appear to be ending up on S3 just fine, but the app is still trying to access the image as "/assets/uploads/entry/image/65/large_IMG_0035.jpg"
Locally, it just shows a broken image, but on Heroku it breaks the whole thing because
ActionView::Template::Error (uploads/entry/image/1/large_IMG_0035.jpg isn't precompiled
The heroku error makes sense to me because it shouldn't be there. I've combed through the app but don't know what's forcing this. I'll post any code anybody thinks will work? Thanks in advance!
Clarification:
Just to clarify, the images are uploading to S3 fine, the problem is how the app is trying to display the image_url
The app is using a local path in the asset pipeline, not the S3 path that it's actually uploading to.
I was having the same issue. In my Carrierwave Initializer I was setting host to s3.amazonaws.com but when I removed that line altogether urls started working.
I hope this helps you resolve your issue, I fought this for several hours!
I believe this issue is related to how you are accessing your image in your view.
If you have mounted an uploader on the field avatar in the following manner:
class User < ActiveRecord::Base
mount_uploader :avatar, AvatarUploader
end
You would access it in your ERB as follows:
<%= image_tag(#user.avatar_url) %>
I would also suggest watching the following Railscast on the topic.
http://railscasts.com/episodes/253-carrierwave-file-uploads
Re-reading issue, I bet it has to do with Carrierwave using Herkou.
Give this a glance and see if it helps.
https://github.com/jnicklas/carrierwave/wiki/How-to%3A-Make-Carrierwave-work-on-Heroku
I am not clear what exactly do you want to achieve.
But for now I have 2 ideas:
For assets host in CDN, you can take a look at this:
https://devcenter.heroku.com/articles/cdn-asset-host-rails31
If you want the images to be part of a model-relation, here's my rough idea:
Put the images path in a table column.
For further information about this you can browse carrierwave github site.(It has many docs and tutorial)

saving photos with paperclip

I have installed paperclip on my rails app (deployed on heroku).
On my localhost it worked fine, but on heroku it didnt work.
I looked at the log and found that this is the problem:
Errno::EACCES(Permission denied - /app/723a45cd/home/public/system):
It looks like it dont have permissions for "system" folder (its the pictures folder).
How I solve this?
Should I give the app permissions? If yes, how?
Thanks,
Oded
I don't think you can store uploaded files on Heroku, you'll have to use S3 as described in their documentation.
Heroku has a read-only file system (except the /tmp directory) which means you'll need to save your images elsewhere. Probably the best place is Amazon S3, which Paperclip happens to support natively.

Ruby on Rails & Prawn PDF

Im creating a PDF Document on my Website.
All works just fine, but when i try to add a Image into the PDF i get
"We're sorry, but something went wrong.
We've been notified about this issue and we'll take a look at it shortly."
So something fails with Prawn.
This is how i try
"image 'logo.png"
i tryed so many ways, all found in the internet, nothing seemed to work.
One was with the BASEDIR, how do i know where BASEDIR is?
Anyway im using OSX Server 10.6 and id be very thankfull to anwser me those questions
-Where is the Prawn Logfile?
-How does one add a Image
Thanks very much,
Greetings!
You'll need to refer to the full path to the file.
We usually refer to our images used in PDFs using the RAILS_ROOT as the starting point. So we use something like:
pdf.image "#{RAILS_ROOT}/public/images/logo-header.png"
Assuming pdf is a Prawn::Document object.

How to copy a file using Paperclip

Does anyone know of a way to copy files with Paperclip using S3 for storage? Before I try to write my own, I just wanted to make sure there wasn't already a way to do this. Thanks
After some more messing around with paperclip, I figured it out. It's ridiculously simple to copy files!
# Stupid example method that just copies a user's profile pic to another user.
def copy_profile_picture(user_1, user_2)
user_2.picture = user_1.picture
user_2.save # Copied the picture and we're done!
end
This also works great with amazon s3. Sweet

Resources