paperclip

Paperclip- validate pdfs with content_type='application/octet-stream'

耗尽温柔 提交于 2019-12-18 11:18:22
问题 I was using paperclip for file upload. with validations as below: validates_attachment_content_type :upload, :content_type=>['application/pdf'], :if => Proc.new { |module_file| !module_file.upload_file_name.blank? }, :message => "must be in '.pdf' format" But, my client complained today that he is not able to upload pdf . After investigating I come to know from request headers is that the file being submitted had content_type=application/octet-stream . Allowing application/octet-stream will

Paperclip- validate pdfs with content_type='application/octet-stream'

社会主义新天地 提交于 2019-12-18 11:17:59
问题 I was using paperclip for file upload. with validations as below: validates_attachment_content_type :upload, :content_type=>['application/pdf'], :if => Proc.new { |module_file| !module_file.upload_file_name.blank? }, :message => "must be in '.pdf' format" But, my client complained today that he is not able to upload pdf . After investigating I come to know from request headers is that the file being submitted had content_type=application/octet-stream . Allowing application/octet-stream will

Rails - Paperclip - How to Check the Image Dimensions before saving

﹥>﹥吖頭↗ 提交于 2019-12-18 10:36:23
问题 I have a Rails 3 app with paperclip. I want to prevent images with a width/height of LTE 50x50 from being saved by paperclip. Is this possible? 回答1: Yep! Here's a custom validation I wrote for my app, it should work verbatim in yours, just set the pixels to whatever you want. def file_dimensions dimensions = Paperclip::Geometry.from_file(file.queued_for_write[:original].path) self.width = dimensions.width self.height = dimensions.height if dimensions.width < 50 && dimensions.height < 50

Migrating from local paperclip storage to S3

泪湿孤枕 提交于 2019-12-18 05:44:19
问题 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

How to copy a file using Paperclip

£可爱£侵袭症+ 提交于 2019-12-18 04:32:13
问题 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 回答1: 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

AWS::S3::S3Object.url_for - How to do this with the new AWS SDK Gem?

不想你离开。 提交于 2019-12-18 02:03:34
问题 I've been using this forever with paperclip and aws-s3: def authenticated_url(style = nil, expires_in = 90.minutes) AWS::S3::S3Object.url_for(attachment.path(style || attachment.default_style), attachment.bucket_name, :expires_in => expires_in, :use_ssl => true) end The new paperclip uses the AWS-SDK gem, which breaks this giving the error: undefined method `url_for' for AWS::S3:Class Anyone know how to get this method to work with the new AWS-SDK gem? 回答1: To generate a url using the aws-sdk

Is it possible to configure Paperclip to produce HTTPS urls for S3?

…衆ロ難τιáo~ 提交于 2019-12-17 22:54:49
问题 I'm using Paperclip to manage user-uploaded images on a site that is served entirely under HTTPS. In order to avoid the silly security warnings on IE7/IE8, I need to also serve these images over SSL. I typically render my images using something like the following: <%= image_tag @product.image.url(:large) %> where class Product < ActiveRecord::Base has_attached_file :image, :styles => { :large => {:geometry => "616x450#"} }, :storage => :s3, :s3_credentials => {:access_key_id => "xxx", :secret

Smarter paperclip validations

拈花ヽ惹草 提交于 2019-12-17 21:52:48
问题 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

model missing required attr_accessor for 'photo_file_name' when uploading with paperclip and S3 on heroku

故事扮演 提交于 2019-12-17 19:20:02
问题 Setting up paperclip with S3 in my linux dev environment was a snap -- everything works out of the box. However, I can't get it to work on Heroku. When I try to do an upload, the log shows: Processing ItemsController#create (for 72.177.97.9 at 2010-08-26 16:35:14) [POST] Parameters: {"commit"=>"Create", "authenticity_token"=>"0Hy3qvQBHE1gvFVaq32HMy2ZIopelV0BHbrSeHkO1Qw=", "item"=>{"photo"=>#<File:/home/slugs/270862_4aa601b_4b6f/mnt/tmp/RackMultipart20100826-6286-1256pvc-0>, "price"=>"342",

model missing required attr_accessor for 'photo_file_name' when uploading with paperclip and S3 on heroku

自闭症网瘾萝莉.ら 提交于 2019-12-17 19:17:01
问题 Setting up paperclip with S3 in my linux dev environment was a snap -- everything works out of the box. However, I can't get it to work on Heroku. When I try to do an upload, the log shows: Processing ItemsController#create (for 72.177.97.9 at 2010-08-26 16:35:14) [POST] Parameters: {"commit"=>"Create", "authenticity_token"=>"0Hy3qvQBHE1gvFVaq32HMy2ZIopelV0BHbrSeHkO1Qw=", "item"=>{"photo"=>#<File:/home/slugs/270862_4aa601b_4b6f/mnt/tmp/RackMultipart20100826-6286-1256pvc-0>, "price"=>"342",