paperclip

Paperclip - Validate File Type but not Presence

ⅰ亾dé卋堺 提交于 2019-11-30 07:30:39
I am using paperclip to handle my file uploads, and in one situation I don't want the file to be mandatory. I do however want to make sure it is a specific file type when it is present. I have this: class TestModel < ActiveRecord::Base #stuff has_attached_file :sound #etc... validates_attachment_content_type :sound, :content_type => ['audio/mp3', 'application/x-mp3'] end And when I have no sound file present, it tells me it is not one of the valid content types. I've tried adding '' to the :content_type array, which also doesn't work! I also attempted creating a lambda procedure for the :if

rails 3 polymorphic association with paperclip and multiple models

空扰寡人 提交于 2019-11-30 07:21:54
I want to make polymorphic associations with paperclip, and allow my user to have one avatar and multiple images. Attachment model: class Attachment < ActiveRecord::Base belongs_to :attachable, :polymorphic => true end class Avatar < Attachment has_attached_file :image, :styles => { :thumb => "150x150>", :view => "260x180>" }, end class Image < Attachment has_attached_file :image, :styles => { :thumb => "150x150>", :view => "260x180>" }, end User Model: has_one :avatar, :as => :attachable, :class_name => 'Attachment', :conditions => {:type => 'avatar'} accepts_nested_attributes_for :avatar

Rails video uploading

随声附和 提交于 2019-11-30 06:48:27
问题 I've searched around for different uploading options for rails and video and Paperclip seems to be pretty good, but are there any others people would recommend, it should have good tutorials and docs because i can't really find any great paperclip docs involving uploading video content. 回答1: We got Paperclip working with video a while back Systems You'll have the same ambiguity whether you use CarrierWave or Paperclip (Rails' two main "attachment" handlers) Any upload system only handles the

Preventing Paperclip from deleting/overwriting attachments on update

喜夏-厌秋 提交于 2019-11-30 06:22:56
I'm having a hard time figuring out how to prevent Paperclip from deleting the old version of an attachment (image). I have a model, Site, which has an attachment, logo. I would like to keep the old logos around since I will be keeping track of changes to the model and would like to view the history of logos. I'm keeping track of the changes in another model, which has a reference to file paths. My problem is that when updating a site with a new logo, Paperclip will flush the old logo first. It surprises me that there's not an option you can switch to prevent Paperclip from flushing the old

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

余生长醉 提交于 2019-11-30 06:21:31
问题 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]",

Rails and Paperclip, default_url not working

北城以北 提交于 2019-11-30 06:04:05
问题 I'm using paperclip for uploading profile pictures. When someone does not upload an image I want a default image to be assigned to the user instead. I'm using this line of code: has_attached_file :avatar, styles: { medium: "300x300>", thumb: "100x100>" }, default_url: "assets/images/:style/male.jpg" But my browser inspector gives me this error: http://localhost:3000/assets/images/original/male.jpg 404 (Not Found) I've tried writing: default_url: "assets/images/:style/male.jpg" default_url:

Get server file path with Paperclip

旧街凉风 提交于 2019-11-30 05:41:26
I'm using Rails with Paperclip to make a small file upload app. I would like to be able to return the file path on the server of the uploaded file once its done but I can't seem to work out how to get the path? Paperclip only seems to record the name of the file itself. Does anybody now how to do this? Assuming you had an attachment called avatar on an instance of a user, you can use user.avatar.path to get the full path of the file on the filesystem, and you can use user.avatar.url to give the path which you could use in image tags and whatnot. Is that what you're meaning? I came cross the

How to save a raw_data photo using paperclip

陌路散爱 提交于 2019-11-30 05:16:17
问题 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

Store image in database using rails paperclip plugin

妖精的绣舞 提交于 2019-11-30 05:09:56
问题 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? 回答1: 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

Using Paperclip to direct upload files to S3

痴心易碎 提交于 2019-11-30 04:14:12
so I've got paperclip set up with uploadify to upload things to S3. I have made my setup so that stuff gets loaded directly to S3 and then when it's done I post to my webserver the results... All I get back is the file name and size. am I supposed to build my own processor or before_post_process method to "download" the file from S3 in order to process it? or am I missing something and uploadify should have provided me a stream with the file inside it after it was done posting to S3? How do you guys go about direct uploads to S3 and then notifying your paperclip backed model? Do you have to