paperclip

How to set a file upload programmatically using Paperclip

江枫思渺然 提交于 2019-11-26 22:31:03
问题 I have a rake task to seed an application with random data using the faker gem. However, we also have images (like logos) that we want uploaded in this rake task. We already have Paperclip set up, but don't have a way to upload them programmatically in a rake task. Any ideas? 回答1: What do you mean by programmatically? You can set up a method that will take a file path along the lines of my_model_instance = MyModel.new file = File.open(file_path) my_model_instance.attachment = file file.close

How Do I Use Factory Girl To Generate A Paperclip Attachment?

妖精的绣舞 提交于 2019-11-26 22:15:26
问题 I have model Person that has many Images, where images has a Paperclip attachment field called data, an abbreviated version displayed below: class Person has_many :images ... end class Image has_attached_file :data belongs_to :person ... end Person is required to have at least one Image attached to it. When using FactoryGirl, I have code akin to the following: Factory.define :image do |a| a.data { File.new(File.join(Rails.root, 'features', 'support', 'file.png')) } a.association :person end

rails paperclip and passenger `is not recognized by the 'identify' command`

喜夏-厌秋 提交于 2019-11-26 21:59:14
When I upload a photo, my model fails validation, err well even without any validations I'm returned this error: /tmp/stream20100103-13830-ywmerx-0 is not recognized by the 'identify' command. and /tmp/stream20100103-13830-ywmerx-0 is not recognized by the 'identify' command. I'm confident this is not related to ImageMagick because I've removed any image processing from the uploading, also I've tried uploading different mime types, like .txt files and the such. Additionally, I found something that may work. A blog post claims that putting the following in my environment (in this case

base64 photo and paperclip -Rails

二次信任 提交于 2019-11-26 21:56:31
问题 I want to handle a base64 photo with paperclip. When I try: photo = Photo.new string = base64string photo.photo = StringIO.new(Base64.decode64(string)) photo.save It does not work. Why? Thanks in advance. 回答1: Make sure that the StringIO you are using is the paperclip opened one. https://github.com/thoughtbot/paperclip/blob/master/lib/paperclip/upfile.rb sio = StringIO.new(Base64.decode64(string)) puts sio.respond_to?(:original_filename) puts sio.respond_to?(:content_type) It needs to have

Ruby on Rails - Paperclip Error

最后都变了- 提交于 2019-11-26 21:14:10
问题 For reference I have been following this tutorial: https://devcenter.heroku.com/articles/paperclip-s3 Except I am in localhost testing right now, so I installed the Figaro gem and placed my S3 info in application.yml. Using Rails v4, Cocaine v0.5.3, and Paperclip v4.1.0 (unsure if any other gem version numbers need to be mentioned). I have a model called SubmissionDetails, where in its new.html.erb I am trying to upload a jpg to a column called attachment. Here is the relevant model code: has

How do I tell paperclip to not save the original file?

风格不统一 提交于 2019-11-26 20:49:43
问题 How do I tell Paperclip not to save the original file when it is uploaded? Or even better, to store a scaled version of the file as the original? 回答1: I believe that you can simply define a style for :original to have paperclip replace the original with that size. :styles => { :original => '300x168>', :cropped_thumb => {:geometry => "115x70#", :jcrop => true}, ...} 回答2: Cris G's solution may be nice at most simple cases but it has limitations. consider that: style :original Paperclip process

NameError (uninitialized constant Paperclip::Storage::S3::AWS):

做~自己de王妃 提交于 2019-11-26 15:56:46
问题 I'm trying to incorporate images into my web app and I keep running into this error after removing quite a few features. It came down to my 'create' application controller and I'm not entirely sure where I should go from here. 2015-02-06T20:30:12.292187+00:00 app[web.1]: (1.9ms) ROLLBACK 2015-02-06T20:30:12.296299+00:00 app[web.1]: NameError (uninitialized constant Paperclip::Storage::S3::AWS): 2015-02-06T20:30:12.296301+00:00 app[web.1]: app/controllers/articles_controller.rb:24:in `create'

Paperclip::Errors::MissingRequiredValidatorError with Rails 4

倖福魔咒の 提交于 2019-11-26 15:01:29
问题 I'm getting this error when I try to upload using paperclip with my rails blogging app. Not sure what it is referring to when it says "MissingRequiredValidatorError" I thought that by updating post_params and giving it :image it would be fine, as both create and update use post_params Paperclip::Errors::MissingRequiredValidatorError in PostsController#create Paperclip::Errors::MissingRequiredValidatorError Extracted source (around line #30): def create @post = Post.new(post_params) This is my

Save image from URL by paperclip

房东的猫 提交于 2019-11-26 14:53:07
Please suggest me a way to save an image from an URL by Paperclip. Here is a simple way: require "open-uri" class User < ActiveRecord::Base has_attached_file :picture def picture_from_url(url) self.picture = open(url) end end Then simply : user.picture_from_url "http://www.google.com/images/logos/ps_logo2.png" Aditya Sanghi In Paperclip 3.1.4 it's become even simpler. def picture_from_url(url) self.picture = URI.parse(url) end This is slightly better than open(url). Because with open(url) you're going to get "stringio.txt" as the filename. With the above you're going to get a proper name of

Validation failed: Upload file has an extension that does not match its contents

£可爱£侵袭症+ 提交于 2019-11-26 13:53:22
问题 I am using paperclip gem to upload files. and my paperclip gem version is paperclip-4.1.1. While uploading a file its throwing Validation failed: Upload file has an extension that does not match its contents. I am trying to upload a xlsx file. and also i have mentioned that into the model content_type. validates_attachment_content_type :upload_file, :content_type => %w(application/msword application/vnd.ms-office application/vnd.ms-excel application/vnd.openxmlformats-officedocument