paperclip

Not losing paperclip attachment when model cannot be saved due to validation error

安稳与你 提交于 2019-11-29 20:19:42
The scenario is a normal model that contains a paperclip attachment along with some other columns that have various validations. When a form to to create an object cannot be saved due to a validation error unrelated to the attachment, columns like strings are preserved and remain prefilled for the user, but a file selected for uploading is completely lost and must be reselected by the user. Is there a standard approach to preserving the attachment in the case of a model validation error? This seems like a very common use case. It seems inelegant to hack up a solution where the file is saved

Rails Paperclip & Multiple File Uploads

纵饮孤独 提交于 2019-11-29 20:01:45
I am looking for a solution to give the user the ability to upload multiple images through one file_field. I have looked in to options such a Jquery File Upload and Uploadify but have yet to come across good examples with a working solution. I already have multiple images setup, has_attached_file :asset, :styles => { :large => "640x480", :medium => "300x300", :thumb => "100x100" }, :storage => :s3, :s3_credentials => "#{Rails.root}/config/s3.yml", :path => "/:contributor_id/:listing_name/:filename" Right now I am displaying 5 individual file_fields def new @listing = Listing.new 5.times {

Paperclip fetch image directly via url

你。 提交于 2019-11-29 18:32:21
问题 It's it possible to fetch an image via url using PaperClip ? It's possible with fleximage, but fleximage has no support for Rails3 so I've switched over to paperclip. At present, I'm fetching the image via curl, saving it on the hdd and load it via image_file of paperclip. I've found no real solution via google, so hopefully you can help me. 回答1: Yes this is possible and amazingly simple. In your model: #we use this to get the image. require 'rest-open-uri' Class Model << ActiveRecord::Base

Paperclip File Not Found Error

半腔热情 提交于 2019-11-29 17:38:43
问题 I just switched from a paperclip rails plugin to a paperclip gem. The project is a rails 2.3 application and I am using paperclip 2.7.2 gem. I am getting the following odd error: identify: unable to open image `file': No such file or directory @ error/blob.c/OpenBlob/2617. identify: no decode delegate for this image format `file' @ error/constitute.c/ReadImage/544. Seems like paperclip is looking for a file called 'file' but I am not sure why. I didn't change any of the code we had before. It

Rails paperclip gem - Get file from private folder

孤者浪人 提交于 2019-11-29 15:34:17
问题 I'm using paperclip to upload files to my server. If I don't specify the path, paperclip saves the file to a public folder, and then I can download it by accessing <%= @user.file.url %> in the view. But if I specify the path to a non-public folder, it's not possible getting the file from the view, obviously. I would like to know some way to download the saved files in a private folder, from the web and from a ruby script. 回答1: The first thing we need to do is add a route to routes.rb for

Nested form using paperclip

爱⌒轻易说出口 提交于 2019-11-29 15:11:48
问题 I have a model called posts, and it has many attachments. The attachments model is using paperclip. I made a standalone model for creating attachments which works just fine, this is the view as instructed here (https://github.com/thoughtbot/paperclip): <% form_for :attachment, @attachment, :url => @attachment, :html => { :multipart => true } do |form| %> <%= form.file_field :pclip %> <%= form.submit %> <% end %> The nested form in posts looks like this: <% @attachment = @posts.attachments

setting content-type for mp4 files on s3

家住魔仙堡 提交于 2019-11-29 14:14:44
I am adding user uploaded videos to my RoRs site with the help of the paperclip gem and s3 storage. For some reason that I can't figure out, whenever a user uploads an mp4 file, s3 sets content-type for that file as application/mp4 instead of video/mp4 . Note that I have registered mp4 mime type in an initializer file: Mime::Type.lookup_by_extension('mp4').to_s => "video/mp4" Here is the relevant part of my Post model: has_attached_file :video, :storage => :s3, :s3_credentials => "#{Rails.root.to_s}/config/s3.yml", :path => "/video/:id/:filename" validates_attachment_content_type :video,

Multi-step form in Rails 3 with Paperclip attachments

元气小坏坏 提交于 2019-11-29 13:49:53
I'm creating a multi-part form in the style that Ryan Bates describes here: http://railscasts.com/episodes/217-multistep-forms http://asciicasts.com/episodes/217-multistep-forms (text-based version) To summarize, I have one view (with a bunch of partials for each form step), and the form variables are stored in a session when the user clicks a next button and a different part of the form is displayed. One of my form steps allows the user to upload several images via the Paperclip gem. The problem with that is that Rails is trying to upload the image data to the session, which is returning

getting random error while upload photo with paperclip on my ftp server

隐身守侯 提交于 2019-11-29 12:45:47
I used gem "paperclip" for upload images and gem "paperclip-storage-ftp" for store images on my own ftp server. It worked fine for a while, but now I am getting random errors, when I upload photos. Sometimes this Net::FTPReplyError - 150 Connecting to port 3270 Sometime this Net::ReadTimeout - Net::ReadTimeout: Sometime this Paperclip::Storage::Ftp::NoServerAvailable .. and sometimes this: Net::FTPPermError - 500 ? Model class AlbumPhoto < ActiveRecord::Base has_attached_file :photo, { # Choose the FTP storage backend :storage => :ftp, :path => "www.abcd.com/:attachment/:id/:style/:filename",

Migrating from local paperclip storage to S3

跟風遠走 提交于 2019-11-29 09:31:40
We've recently moved to a new webhost that offers limited storage space so we're trying to move all of our user uploads (Avatars, Files, etc.) uploaded via the Paperclip gem to Amazon S3. I have several hundred files all corresponding to different models that I'm now trying to migrate en masse. I found this document that introduces a nifty paperclip rake task: rake paperclip:refresh:missing_styles This command does some of the work for me, however, I noticed it's only setting up the files structure without sending any data - in addition it's not setting up any thumbnails defined using the