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.
Related
I copied this question from https://groups.google.com/forum/#!msg/rubyonrails-talk/9Wfid1pYP7w/qqSIiW45L_8J
I have the same problem with him, please help me, thanks a lot
Hello Everyone,
I am using Wicked Pdf to generate pdf file.
In my model, i have method to generate pdf file.
I also need to show image in my pdf file from amazon s3.
Case 1:
i tried using
While i am running that method image not displaying, just a small box only appearing insteat of image.
Case 2:
i tried <%= image_tag(#image.avatar)%>
While i run this, i am getting "rake aborted!
undefined method `image_tag' for main:Object"
i googled this problem but no clear answer... any help..
First of all you need to use wicked_pdf_image_tag to show images in pdf. Try it with some local image:
<%= wicked_pdf_image_tag "some_image.jpg" %>
This should work.
Then try it with s3 image. If image doesn't show up, this mean that you using old version of wkhtmltopdf library. Download new version from http://wkhtmltopdf.org/downloads.html
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
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)
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
How do I upload images and zip files in RoR? I am a newbie. So please help.
Give me both the view and the controller code example.
Thanks in advance.
Nav,
Try the paperclip plugin, you can read about it here http://www.thoughtbot.com/projects/paperclip
We prefer CarrierWave for image uploads in Rails. Very easy to integrate and very modular.
The following post describes a solution for image uploading using CarrierWave while image transformations are done seamlessly in the cloud. Uploaded images are stored in the cloud and delivered through a CDN.
No need to install RMagick, MiniMagick and ImageMagick.
http://cloudinary.com/blog/ruby_on_rails_image_uploads_with_carrierwave_and_cloudinary
suggest checking out the Railscast for paperclip.
ImageMagick is also pretty cool
I would recommend paperclip, and the patch that allows you to store the content in the database instead of the file system
http://patshaughnessy.net/paperclip-database-storage
the link has the view and controller examples that you are looking for
I prefer carrierwave is better to upload images easily.
Here's github page , and railscasts page for quick start.
One option is attachment_fu. It allows you to save your uploaded file to the filesystem, database, or Amazon S3. It also allows you to select which image processor is used, such as RMagick or Minimagick.
The link provides better code than I could here.