
Security News
The Changelog Podcast: Practical Steps to Stay Safe on npm
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.
carrierwave-yandexfotki
Advanced tools
This gem provides a simple way to upload image files from Rails application to fotki.yandex.ru service.
In Rails, add it to your Gemfile:
gem 'carrierwave-yandexfotki'
Start off by creating an uploader:
app/uploaders/image_uploader.rb
It should look something like this:
class ImageUploader < CarrierWave::Uploader::Base
storage CarrierWave::Storage::YandexFotki
yandex_login 'login'
yandex_password 'password'
##
# Uncomment this if you want use 'net/http' library instead 'curb'.
# Also you need install 'multipart-post' gem for use this option.
#
#yandex_net_http true
##
# This required for removing old image from fotki.yandex.ru
# on updating image attached to model
#
before :cache, :remove_old_file_before_cache
def remove_old_file_before_cache(new_file)
remove! unless blank?
end
end
Add a string column to the model you want to mount the uploader on:
add_column :products, :image, :string
Open your model file and mount the uploader:
class Product
mount_before_save_uploader :image, ImageUploader
end
NOTE! You should use mount_before_save_uploader instead default mount_uploader method for YandexFotki storage.
Now you can assign files to the attribute, they will automatically be uploaded when the record is saved.
product = Product.new
product.image = params[:file]
product.save!
product.image.url # => 'http://img-fotki.yandex.ru/get/path/to/file_orig'
You can get different versions (sizes) of the same image from fotki.yandex.ru (without need to resize images on your server):
product.image.url # original size image url
product.image.url(:xl) # image fitted to 800x800 px square
product.image.url(100) # image fitted to 100x100 px square
All available sizes:
Size | Side of the bounding square, px
---------------+----------------------------------
:orig or nil | Original size
:xl or 800 | 800
:l or 500 | 500
:m or 300 | 300
:s or 150 | 150
:xs or 100 | 100
:xxs or 75 | 75
:xxxs or 50 | 50
You can find this info on this page: http://api.yandex.ru/fotki/doc/appendices/photo-storage.xml
FAQs
Unknown package
We found that carrierwave-yandexfotki demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.

Security News
Ruby's creator Matz assumes control of RubyGems and Bundler repositories while former maintainers agree to step back and transfer all rights to end the dispute.