paperclip

Validate Attachment Content Type Paperclip

牧云@^-^@ 提交于 2019-11-30 21:32:43
Is it possible to enforce a 'content type' validation in paperclip without enforcing a 'presence' validation (i.e. allow blanks)? I currently have: class Person < ActiveRecord::Base has_attached_file :picture validates_attachment_content_type :picture, :content_type => ['image/jpeg', 'image/jpg', 'image/png'] end However, this fails if no attachment is present. For example: >> @person = Person.new >> @person.save >> @person.errors.first => ["picture_content_type", "is not one of image/jpeg, image/jpg, image/png"] Is it possible to do the validation only if an attachment is included. I'm not

How to save a raw_data photo using paperclip

不打扰是莪最后的温柔 提交于 2019-11-30 20:45:10
I'm using jpegcam to allow a user to take a webcam photo to set as their profile photo. This library ends up posting the raw data to the sever which I get in my rails controller like so: def ajax_photo_upload # Rails.logger.info request.raw_post @user = User.find(current_user.id) @user.picture = File.new(request.raw_post) This does not work and paperclip/rails fails when you try to save request.raw_post. Errno::ENOENT (No such file or directory - ????JFIF??? I've seen solutions that make a temporary file but I'd be curious to know if there is a way to get Paperclip to automatically save the

Store image in database using rails paperclip plugin

▼魔方 西西 提交于 2019-11-30 20:32:26
I have an application that uses the Paperclip plugin for image upload. Now that app should get deployed to an host(heroku) which has a read-only file system. Can I somehow tell paperclip to store the images in the database? Check out this sample app http://patshaughnessy.net/2009/5/29/paperclip-sample-app-part-3-saving-file-attachments-in-a-database-blob-column I guess this is exactly what you need. HTH PS: storing images in db is usually a bad idea, I am sure you can use paperclip with S3 / cloudfront ( as mentioned in the answers below ) Heroku recommends storing file uploads on s3, and

Create paperclip attachment from rmagick image

人走茶凉 提交于 2019-11-30 18:56:12
I have a problem to find a way to save an image created with RMagick in a paperclip attachment. imageList = Magick::ImageList.new imageList.new("images/apple.gif", "images/overlay.png") ... picture = imageList.flatten_images I am in a model that have an attached file has_attached_file :picture, :url => ..., :path => ... and i just want my image returned by imageList.flatten_images to be saved as the picture of my model. Does anyone know how to do it easily please? thanks jordinl Let's see if that's what you need picture = imageList.flatten_images file = Tempfile.new('my_picture.jpg') picture

Validate extension in Paperclip - Ruby on Rails

倖福魔咒の 提交于 2019-11-30 18:53:31
I've found that Paperclip can validate file content type, i.e. image/jpeg, but I want to specifically validate the extension. This is because I'm working with an obscure extension that won't get a consistent content type. Anyone know if this is doable, or a good way to do this? Guess, there is no need to validate it with paperclip's method. You can rather use something like: has_attached_file :attachment validates_format_of :attachment_file_name, :with => %r{\.(docx|doc|pdf)$}i Edit: Alternatively, to validate it with paperclip: validates_attachment_content_type :attachment, :content_type =>

How to Upload Multiple Image in Rails 4 Using Paperclip

三世轮回 提交于 2019-11-30 18:32:06
问题 I am trying to create a gallery of Images for my Markets controller here I am able to to use paperclip to upload single image .I search on google but I haven't find any solution . How can I upload multiple images and show it in the form of gallery using paperclip . is there any way . Please suggest me the answer . 回答1: Here is the article, which explains in details, how to achieve it. Some code snippets from there are below. Models: # app/models/market.rb class Market < ActiveRecord::Base has

Paperclip Error: NotIdentifiedByImageMagickError

醉酒当歌 提交于 2019-11-30 18:13:06
I've had a rails install with Paperclip working just fine for a while now and in a recent deploy it has broken. I believe it coincided with a gemfile update, because nothing else on the machine has changed. The error is: Command :: file -b --mime :file [paperclip] Error while determining content type: Command 'file -b --mime :file' returned 1. Expected 0 This is on a png file that I've verified to be valid. When I run 'file -b --mime' on the image I get: image/png; charset=binary I also get this afterwards: Command :: identify -format %wx%h :file [paperclip] An error was received while

ruby copy a paperclip attachment from one model to another?

两盒软妹~` 提交于 2019-11-30 17:14:19
I have two models like this:- Model 1 - card - contains a representation of data of interest for front page attachment name = cardimage Model 2 - user - contains the user attachment name = avatar When I create! a new card, I want the avatar from the user model to be copied to the card model as a new cardimage. Is there a simple one liner for this? Ruby/Rails/Paperclip This should do the trick, you could use an after_create callback if the models are associated, if not I would recommend doing it in the controller action that creates the card. instance_of_model_one.cardimage = instance_of_model

Validate Attachment Content Type Paperclip

*爱你&永不变心* 提交于 2019-11-30 17:12:44
问题 Is it possible to enforce a 'content type' validation in paperclip without enforcing a 'presence' validation (i.e. allow blanks)? I currently have: class Person < ActiveRecord::Base has_attached_file :picture validates_attachment_content_type :picture, :content_type => ['image/jpeg', 'image/jpg', 'image/png'] end However, this fails if no attachment is present. For example: >> @person = Person.new >> @person.save >> @person.errors.first => ["picture_content_type", "is not one of image/jpeg,

AWS Api Gateway as a HTTP Proxy is currupting binary uploaded image files

爷,独闯天下 提交于 2019-11-30 16:55:54
I have a ruby on rails app that takes an image file, "attaches it to a member", and uploads it to s3. When I use insomnia and POST directly to the app ... it works , however when I use the exact same endpoint behind AWS Api Gateway, the image is corrupt and not viewable. Here is the comparison of the requests. LEFT = directly posted to the rails app RIGHT = through api gateway https://www.diffchecker.com/wwUmpB5W Something I noticed, is that the paperclip gem is running different commands. It's evident that paperclip realized that the file is not an image when being passed through API gateway.