trouble with dots using rails paperclipftp - ruby-on-rails

I got trouble with paperclipftp
Here my config :
has_attached_file :resume_img, :styles => { :thumb => "100x100#",:screen => '690x780#' },:retina => { :quality => 70 },
:path => "username.com/uploads/:attachment/:id/:style/:filename",
:url => "http://username.com/:attachment/:id/:style/:filename",
:storage => :ftp,
:ftp_credentials => { :host => 'ftp.username.com', :username => 'username', :password => '*******' },
:ftp_passive_mode => false,
:ftp_timeout => 90,
:ftp_verify_size_on_upload => false,
:ftp_debug_mode => false
My FTP is hosted by dreamhost, I need to upload inside the folder username.com but something strange appears rails escape the dots so it upload to usernamecom/uploads/
It does the same with the url it try to find the image at http://usernamecom/
Any idea???

Try it maybe escaped with
"username\.com/uploads/:attachment/:id/:style/:filename"

Related

URL issue: paperclip-av-transcoder

I am trying to implement paperclip-av-transcoder gem. I have checked everything but not able to find what I am doing wrong here. I'm writing steps which I have followed.
Added into gemfile
--> gem 'paperclip-av-transcoder'
Added into my model
--> has_attached_file :video_file, :styles => {
:medium => { :geometry => "640x480", :format => 'mp4' },
:thumb => { :geometry => "100x100#", :format => 'jpg', :time => 10 }
}, :processors => [:transcoder]
--> validates_attachment_content_type :video_file, :content_type => /\Avideo\/.*\Z/
created schema to add column name
"video_file_meta"
In my view file
video_tag(video.video_file.url, controls: true, autobuffer: true, size: "320x240")
I have checked video in public/system folder it is properly saved I am able to see that video there but I am not able to see that in my view file.
Video Url -> /system/videos/video_files/000/000/003/original/tingtong_464.mp4?1497851104
I am sharing screens to show how it looks in the browser.
Everything from my point is correct, except Paperclip requires at least one field in database - *_file_name (for you it's video_file_file_name), but you didn't added it and Paperclip can't construct url properly. Read more https://github.com/thoughtbot/paperclip#usage
Currently working model file code:
has_attached_file :video_file, :styles => {
:medium => { :geometry => "500x500", :format => 'jpg' },
:thumb => { :geometry => "100x100", :format => 'jpg' }
}, :processors => [:transcoder]
validates_attachment_content_type :video_file,
:content_type => [
"video/mp4",
"video/quicktime",
"video/3gpp",
"video/x-ms-wmv",
"video/mov",
"video/flv",
],
:message => "Sorry! We do not accept the attached file type"
I guess I am not resizing my video file in any other video format so it is working properly.

Rails and Paperclip storing images in a specific path sets wrong URL

I want to store my images using the normal file storage adapter.
This is my PAPERCLIP_STORAGE_OPTS:
PAPERCLIP_STORAGE_OPTS = {
:styles => { :thumb => '170x170!#', :medium => '450x300!>', :large => '600x400!>',:desktop => '750x300!>'},
:convert_options => { :all => '-quality 100' },
:processor => [ :papercrop ],
:path => "/opt/www/myapp/images/:class/:attachment/:id_partition/:style/:filename"
}
This is my model :
class User < ActiveRecord::Base
attr_accessor :PAPERCLIP_STORAGE_OPTS
has_attached_file :user_photo, PAPERCLIP_STORAGE_OPTS_THUMB
When a user uploads a photo - it actually does store the image in the correct location on my system:
/opt/www/myapp/images/users/user_photos/000/000/050/original/picture
However when I go to show the image, like this :
<%=image_tag current_user.user_photo.url(:thumb), :height=> "30", :width=> "30" %>
The image is not found, and in my logs I see the image request at this URL:
ActionController::RoutingError (No route matches [GET] "/system/users/user_photos/000/000/050/thumb/picture"):
And the full URL created is :
https://www.myapp.com/system/users/user_photos/000/000/050/thumb/picture?1460285803 - which doesnt resolve.
How can I configure paperclip to allow my images to be stored in this particular url /opt/www/myapp/images/ and still be accessed and linked to correctly through Paperclip in my rails app?
You will have to set URL option:
for me it was:
has_attached_file :avatar, :styles => { :medium => "300x300>", :thumb => "100x100>", :small=>"60x60>" },
:path => ':rails_root/public/system/:class/:id/:style/:filename',
:url => '/system/:class/:id/:style/:filename'
Not sure for your case as you store images in the app folder directly so you may try(test it from console and modify it):
:path => "/opt/www/myapp/images/:class/:attachment/:id_partition/:style/:filename",
:url => '/images/:class/:attachment/:id_partition/:style/:filename'

Upload image using paperclip, fog and rackspace

I need to upload an logo image to rackspace using fog & paperclip.
Paperclip::Attachment.default_options.update({
:path => "images/:class/:id/:attachment/:style/img_:fingerprint",
:storage => :fog,
:fog_credentials => {
:provider => 'Rackspace',
:rackspace_username => 'blablabla',
:rackspace_api_key => 'blablabla',
:persistent => false
},
:fog_directory => 'blablabla',
:fog_public => true,
:fog_host => 'http://blablabla.rackcdn.com'
})
I have this settings in config/initializers/paperclip_defaults.rb
But how to initialize the logo to catch those settings. Please help me i was in a confusion here.
You don't need to initialize the logo to "catch" those settings
Let me explain how it works:
Paperclip simply creates an entry into your db, and stores your file on Rackspace. Accessing the file, with paperclip will simply be a case of ensuring paperclip is able to load the RackSpace URL correctly
I would do this:
#config/application.rb
config.paperclip_defaults = {
styles: { :medium => "x500", :thumb => "x200" },
default_url: "placeholder.png"
}
#config/environments/production.rb
Paperclip::Attachment.default_options.merge!({
:path => "images/:class/:id/:attachment/:style/img_:fingerprint",
:storage => :fog,
:fog_credentials => {
:provider => 'Rackspace',
:rackspace_username => 'blablabla',
:rackspace_api_key => 'blablabla',
:persistent => false
},
:fog_directory => 'blablabla',
:fog_public => true,
:fog_host => 'http://blablabla.rackcdn.com'
})
This allows you to upload to Rackspace in production mode. You don't need to change the model, and would call your paperclip objects like this:
#model.image.url #-> yields rackspace URL
If you need more help / clarity, please let me know. I have just used your Rackspace code & moved from an initializer to your config files

Rails paperclip amazon aws s3 gem, how to change image url?

In my model I have:
has_attached_file :image,
:storage => :s3,
:styles => { :original => ["300x250>", :png], :small => ["165x138>", :png], :mini => ["120x120>", :png] },
:path => 'images/vind/:style/:id/:basename.:extension',
:url => 'images/vind/:style/:id/:basename.png',
:bucket => 'konkurrencerher',
:s3_credentials => {
:access_key_id => 'x',
:secret_access_key => 'x'
}
The problem is just that there is added the amazon s3 hostname to the url in view.
I have a solution to this, but is a bit ugly:
<%= image_tag(kon.photo.image.url(:small).gsub("http://s3.amazonaws.com/konkurrencerher", ""), :class => 'koni') %>
But, how is it possible to define the image url in the model, without the Amazon S3 hostname?
Take a look at Paperclip::Storage::S3, especially on the :s3_host_alias.
You can try configuring your has_attached_file with the following additional options
:url => ':s3_alias_url',
:s3_host_alias => "example.domain.net"
Hope this helps.
My solution created a file in the initializers map with this:
Paperclip.interpolates(:s3_path_url) { |attachment, style|
"#{(attachment.path).gsub("images/", "")}"
}
And then the url should be:
:url => ':s3_path_url'
This is a much better solution.

How do I get Paperclip to recognize custom processors instead of just pushing styles through to thumbnail?

I am not having any problem getting the custom processor to load, however when I try to call it from has_attached_file, paperclip ignores it, and instead just runs thumbnail.
model
has_attached_file :file,
:styles => { :web => "some input" },
:processors => [ :custom ],
:url => ":class/:id/:style/:basename.:extension",
:path => ":class/:id/:style/:basename.:extension"
:storage => :s3
As simple a processor as can be made just to show that the processor has been run
processor.rb
module Paperclip
class Custom < Processor
attr_accessor :input
def initialize(file, options = {}, attachment = nil)
super
#basename = File.basename(file.path, File.extname(file.path))
end
def make
dst = Tempfile.new([ #basename, 'jpg' ].compact.join("."))
dst
end
end
end
But instead when I check the saved record it returns instance variables from thumbnail
>record.file.styles
{:web=>
#<Paperclip::Style:0x00000102f185d0
#attachment=
http://s3.amazonaws.com/bucket/model/id/base_name/file_name.jpg,
#format=nil,
#geometry="some_input",
#name=:web,
#other_args={}>}
I must be missing something in either writing the processor or calling it. Any idea what is going on here?
Have you tried something like this?
has_attached_file :file,
:styles => {
:my_super_style => {:geometry => "100x100#", :foo => "bar", :processors => [:custom]}
},
Have you put in the right place?
lib/paperclip_processors/custom.rb
:styles => { :web => "some input" },
:processors => [ :custom ],
should be:
:styles => {
:web => {:geometry => "some input", :processors => [:custom]},

Resources