paperclip

Uploading an image from Android (with Android Asynchronous Http Client) to rails server (with paperclip)

萝らか妹 提交于 2019-11-28 17:39:33
I'm trying to upload an image file via http post method from android device to rails server. But posting an image is not working. More specifically, the post parameter (including image file) doesn't seem to be sent correctly. I'm using Android Asynchronous Http Client (http://loopj.com/android-async-http/) to post an image from android, and the code for posting image is like this. public static void postImage(){ RequestParams params = new RequestParams(); params.put("picture[name]","MyPictureName"); params.put("picture[image]",File(Environment.getExternalStorageDirectory().getPath() + "

Smarter paperclip validations

早过忘川 提交于 2019-11-28 16:54:09
I'm using paperclip in a rails app and have the following three validations in my model validates_attachment_presence :photo validates_attachment_size :photo, :less_than=>1.megabyte validates_attachment_content_type :photo, :content_type=>['image/jpeg', 'image/png', 'image/gif'] If the user forgets to add an attachment, all three validations fail and thus, the user is presented with the following three errors: # Photo file name must be set. # Photo file size file size must be between 0 and 1048576 bytes. # Photo content type is not included in the list I think it would be best to just show the

Simple cropping with Paperclip

跟風遠走 提交于 2019-11-28 16:41:14
I would like to crop images on upload using Paperclip to get square thumbs from the center of the original picture. I find out a method in documentation that seems to do exactly what I want: transformation_to(dst, crop = false) The problem is that I can't figure out where to use this method. It would be great to simply pass something as a parameter here: has_attached_file :picture, :styles => { :medium => "600x600>", :thumb => "something here" } You only need to use # instead of > as a parameter: has_attached_file :picture, :styles => { :thumb => "200x200#" } 来源: https://stackoverflow.com

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

泪湿孤枕 提交于 2019-11-28 16:21:28
问题 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

Rails Paperclip & Multiple File Uploads

∥☆過路亽.° 提交于 2019-11-28 15:53:36
问题 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/

Resize an image with Paperclip

一世执手 提交于 2019-11-28 15:37:58
问题 The Paperclip plugin for Rails has a resize option that keeps the image in proportion. According to Ryan Bates' Paperclip Railscast, to make sure that option is on, you have to add a greater-than sign in the end of the size for the style you're looking to resize, as such: :styles => { :small => "160x160>" } I'm looking for Paperclip to resize my image to an exact size, even if that means it being out of proportion, so I figured that removing the greater-than sign would do the trick, as such:

How can I set paperclip's storage mechanism based on the current Rails environment?

雨燕双飞 提交于 2019-11-28 15:13:21
I have a rails application that has multiple models with paperclip attachments that are all uploaded to S3. This app also has a large test suite that is run quite often. The downside with this is that a ton of files are uploaded to our S3 account on every test run, making the test suite run slowly. It also slows down development a bit, and requires you to have an internet connection in order to work on the code. Is there a reasonable way to set the paperclip storage mechanism based on the Rails environment? Ideally, our test and development environments would use the local filesystem storage,

Nested paperclip form with multiple images

喜夏-厌秋 提交于 2019-11-28 12:35:30
I have a one-to-many association between a Banana model and an Image model. In addition, each Banana and Image belong to a User (via a separate association because an Image and its Banana might have different Users). I would like a nested form to create Bananas as well as Images. The kicker is that I don't know how many Images to build (note the multiple attribute). The commented out bit of the form below will create the appropriate amount of Images, but won't complete the associated User reference. Is there a way to accomplish this with fields_for (so the associations are completed) as I've

I can't install paperclip

余生颓废 提交于 2019-11-28 12:15:32
I'm new in rails, I need to install Peperclip ( https://github.com/thoughtbot/paperclip ) and i can't, I have looked every tutorial I can find and I haven't been able to find where is the bug. I installed the ImageMagick and follow all the instruction of github. When I run: rails generate paperclip club imagen I got this /Users/Moski/.rvm/gems/ruby-2.0.0-p451@railstutorial_rails_4_0/gems/railties-4.0.4/lib/rails/generators/actions/create_migration.rb:13:in `migration_file_name': protected method `migration_file_name' called for #<PaperclipGenerator:0x000001053fbb68> (NoMethodError) from /Users

setting content-type for mp4 files on s3

烈酒焚心 提交于 2019-11-28 08:05:48
问题 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