SlideShare a Scribd company logo
CarrieWave
についてざっくり解説
ota42y
2017/01/25 Shinjuku.rb #45
自己紹介
ota42y
ヘルスケア系の会社勤務(人募集中)
rubyとかgoとかC++とか
負債の消し方、探してます
リリースされました
招待コードota42y で入れます( ゚∀゚)o彡゚
CarrierWave
https://github.com/bbatsov/rubocop
A simple and extremely exible way to upload les
It works well with Rack based web applications
Cloud services support (AWS, google...)
ActiveRecord integration
Sample Code
class AvatarUploader < CarrierWave::Uploader::Base
storage :file
end
my_file = File.open('icon.png')
uploader = AvatarUploader.new
uploader.store!(my_file)
uploader.retrieve_from_store!('inoc.png')
upload to le (icon.png)
Write setting to uploader class
save path, extension whitelist, convert ....
UploadSetting
class MyUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
process resize_to_fit: [800, 800]
version :thumb do
process resize_to_fill: [200,200]
end
def extension_whitelist
%w(jpg png)
end
storage :fog
def store_dir
"uploads/images"
end
end
Croud services support
use fog gem internally
https://github.com/fog/fog
support many service
AWS, Google, Rackspace...
CarrieWave provide generate access url method
ActiveRecord integration
Save le to database column
class User < ActiveRecord::Base
mount_uploader :icon, AwsUploader
end
u = User.first
u.icon = File.open('default_icon.png')
u.save!
u.icon.url # https://s3.amazonaws.com/path/to/file.png
u.icon_identifier # => 'default_icon.png'
When save model, upload le by uploader
Store the lename to column
ActiveRecord integration
CarrierWave don't store le to database
Store le to folder or clound (Uploader setting)
This gem store lename to database
(CarrierWave call identifier )
Uploader class provide le from lename
ActiveRecord integration
class User < ActiveRecord::Base
mount_uploader :icon, AwsUploader
end
mounter_uploader create these method
def icon
# return AwsUploader object
end
def icon=(new_file)
# set file to AwsUploader
end
def icon_identifier
# return filename
end
ActiveRecord integration
class User < ActiveRecord::Base
mount_uploader :icon, AwsUploader
end
And these save methods
def store_icon!
# save file using AwsUploader
end
def write_icon_identifier
# save filename to database
end
ActiveRecord integration
class User < ActiveRecord::Base
mount_uploader :icon, AwsUploader
end
And register these callbacks
after_save :"store_#{column}!"
before_save :"write_#{column}_identifier"
ActiveRecord integration
class User < ActiveRecord::Base
mount_uploader :icon, AwsUploader
end
u = User.first
u.icon = File.open('default_icon.png')
# call icon=(filename) method and set file to AwsUploader
u.save!
# Call `write_inoc_identifier` from before save callback.
# Write 'default_icon.png' to inon column attribute.
# (call `write_attribute(:inoc, 'default_icon.png')`
# So filename will store to ActiveRecord save! method.
# Call `store_icon` from after save callback
# This method store file using AwsUploader
ActiveRecord integration
class User < ActiveRecord::Base
mount_uploader :icon, AwsUploader
end
u = User.first
u.icon = File.open('default_icon.png')
u.save!
CarrierWave generate access url from lename
u.icon.url
# generate stored file's url
u.icon_identifier
# return filename in database ('default_icon.png')
Save le to lesystem
path = ::File.expand_path(store_path, store_root)
if uploader.move_to_store
file.move_to(path, file_permissions, dir_permissions)
else
file.copy_to(path, file_permissions, dir_permissions)
end
We can change copy or move by uploader setting
https://github.com/carrierwaveuploader/carrierwave
/blob/c45699c318ca895f89fa3304204e48b5f1c411
f1/lib/carrierwave/uploader/store.rb#L53
Save le to cloud
fog_file = new_file.to_file
@content_type ||= new_file.content_type
@file = directory.files.create({
:body => (fog_file ? fog_file : new_file).read,
:content_type => @content_type,
:key => path,
:public => @uploader.fog_public
}.merge(@uploader.fog_attributes))
fog_file.close if fog_file && !fog_file.closed?
use fog gem!
https://github.com/carrierwaveuploader/carrierwave
/blob/c45699c318ca895f89fa3304204e48b5f1c411
f1/lib/carrierwave/storage/fog.rb#L306

More Related Content

What's hot

Packer, where DevOps begins
Packer, where DevOps beginsPacker, where DevOps begins
Packer, where DevOps begins
Jeff Hung
 
(APP202) Deploy, Manage, and Scale Your Apps with AWS OpsWorks and AWS Elasti...
(APP202) Deploy, Manage, and Scale Your Apps with AWS OpsWorks and AWS Elasti...(APP202) Deploy, Manage, and Scale Your Apps with AWS OpsWorks and AWS Elasti...
(APP202) Deploy, Manage, and Scale Your Apps with AWS OpsWorks and AWS Elasti...
Amazon Web Services
 
PowerShell User Group Hamburg - PowerCLI
PowerShell User Group Hamburg - PowerCLIPowerShell User Group Hamburg - PowerCLI
PowerShell User Group Hamburg - PowerCLI
Markus Kraus
 
Deep Dive into AWS CLI - the command line interface
Deep Dive into AWS CLI - the command line interfaceDeep Dive into AWS CLI - the command line interface
Deep Dive into AWS CLI - the command line interface
John Varghese
 
Caldera Learn - LoopConf WP API + Angular FTW Workshop
Caldera Learn - LoopConf WP API + Angular FTW WorkshopCaldera Learn - LoopConf WP API + Angular FTW Workshop
Caldera Learn - LoopConf WP API + Angular FTW Workshop
CalderaLearn
 
Rackspace Hack Night - Vagrant & Packer
Rackspace Hack Night - Vagrant & PackerRackspace Hack Night - Vagrant & Packer
Rackspace Hack Night - Vagrant & Packer
Marc Cluet
 
Amazon Route53へのドメイン移管
Amazon Route53へのドメイン移管Amazon Route53へのドメイン移管
Amazon Route53へのドメイン移管
Jin k
 
TLS305 Using DynamoDB with the AWS SDK for PHP - AWS re: Invent 2012
TLS305 Using DynamoDB with the AWS SDK for PHP - AWS re: Invent 2012TLS305 Using DynamoDB with the AWS SDK for PHP - AWS re: Invent 2012
TLS305 Using DynamoDB with the AWS SDK for PHP - AWS re: Invent 2012
Amazon Web Services
 
Deep Dive: AWS Command Line Interface
Deep Dive: AWS Command Line InterfaceDeep Dive: AWS Command Line Interface
Deep Dive: AWS Command Line Interface
Amazon Web Services
 
Becoming a Command Line Expert with the AWS CLI (TLS304) | AWS re:Invent 2013
Becoming a Command Line Expert with the AWS CLI (TLS304) | AWS re:Invent 2013Becoming a Command Line Expert with the AWS CLI (TLS304) | AWS re:Invent 2013
Becoming a Command Line Expert with the AWS CLI (TLS304) | AWS re:Invent 2013
Amazon Web Services
 
Deep Dive - Advanced Usage of the AWS CLI
Deep Dive - Advanced Usage of the AWS CLIDeep Dive - Advanced Usage of the AWS CLI
Deep Dive - Advanced Usage of the AWS CLI
Amazon Web Services
 
用Tornado开发RESTful API运用
用Tornado开发RESTful API运用用Tornado开发RESTful API运用
用Tornado开发RESTful API运用
Felinx Lee
 
Masterclass Advanced Usage of the AWS CLI
Masterclass Advanced Usage of the AWS CLIMasterclass Advanced Usage of the AWS CLI
Masterclass Advanced Usage of the AWS CLI
Danilo Poccia
 
The Coolest Symfony Components you’ve never heard of - DrupalCon 2017
The Coolest Symfony Components you’ve never heard of - DrupalCon 2017The Coolest Symfony Components you’ve never heard of - DrupalCon 2017
The Coolest Symfony Components you’ve never heard of - DrupalCon 2017
Ryan Weaver
 
(DEV301) Advanced Usage of the AWS CLI | AWS re:Invent 2014
(DEV301) Advanced Usage of the AWS CLI | AWS re:Invent 2014(DEV301) Advanced Usage of the AWS CLI | AWS re:Invent 2014
(DEV301) Advanced Usage of the AWS CLI | AWS re:Invent 2014
Amazon Web Services
 
Power shell examples_v4
Power shell examples_v4Power shell examples_v4
Power shell examples_v4
JoeDinaso
 
Baking in the cloud with packer and puppet
Baking in the cloud with packer and puppetBaking in the cloud with packer and puppet
Baking in the cloud with packer and puppet
Alan Parkinson
 
Usecase examples of Packer
Usecase examples of Packer Usecase examples of Packer
Usecase examples of Packer
Hiroshi SHIBATA
 
Ruby conf 2011, Create your own rails framework
Ruby conf 2011, Create your own rails frameworkRuby conf 2011, Create your own rails framework
Ruby conf 2011, Create your own rails framework
Pankaj Bhageria
 
Phinx talk
Phinx talkPhinx talk
Phinx talk
Michael Peacock
 

What's hot (20)

Packer, where DevOps begins
Packer, where DevOps beginsPacker, where DevOps begins
Packer, where DevOps begins
 
(APP202) Deploy, Manage, and Scale Your Apps with AWS OpsWorks and AWS Elasti...
(APP202) Deploy, Manage, and Scale Your Apps with AWS OpsWorks and AWS Elasti...(APP202) Deploy, Manage, and Scale Your Apps with AWS OpsWorks and AWS Elasti...
(APP202) Deploy, Manage, and Scale Your Apps with AWS OpsWorks and AWS Elasti...
 
PowerShell User Group Hamburg - PowerCLI
PowerShell User Group Hamburg - PowerCLIPowerShell User Group Hamburg - PowerCLI
PowerShell User Group Hamburg - PowerCLI
 
Deep Dive into AWS CLI - the command line interface
Deep Dive into AWS CLI - the command line interfaceDeep Dive into AWS CLI - the command line interface
Deep Dive into AWS CLI - the command line interface
 
Caldera Learn - LoopConf WP API + Angular FTW Workshop
Caldera Learn - LoopConf WP API + Angular FTW WorkshopCaldera Learn - LoopConf WP API + Angular FTW Workshop
Caldera Learn - LoopConf WP API + Angular FTW Workshop
 
Rackspace Hack Night - Vagrant & Packer
Rackspace Hack Night - Vagrant & PackerRackspace Hack Night - Vagrant & Packer
Rackspace Hack Night - Vagrant & Packer
 
Amazon Route53へのドメイン移管
Amazon Route53へのドメイン移管Amazon Route53へのドメイン移管
Amazon Route53へのドメイン移管
 
TLS305 Using DynamoDB with the AWS SDK for PHP - AWS re: Invent 2012
TLS305 Using DynamoDB with the AWS SDK for PHP - AWS re: Invent 2012TLS305 Using DynamoDB with the AWS SDK for PHP - AWS re: Invent 2012
TLS305 Using DynamoDB with the AWS SDK for PHP - AWS re: Invent 2012
 
Deep Dive: AWS Command Line Interface
Deep Dive: AWS Command Line InterfaceDeep Dive: AWS Command Line Interface
Deep Dive: AWS Command Line Interface
 
Becoming a Command Line Expert with the AWS CLI (TLS304) | AWS re:Invent 2013
Becoming a Command Line Expert with the AWS CLI (TLS304) | AWS re:Invent 2013Becoming a Command Line Expert with the AWS CLI (TLS304) | AWS re:Invent 2013
Becoming a Command Line Expert with the AWS CLI (TLS304) | AWS re:Invent 2013
 
Deep Dive - Advanced Usage of the AWS CLI
Deep Dive - Advanced Usage of the AWS CLIDeep Dive - Advanced Usage of the AWS CLI
Deep Dive - Advanced Usage of the AWS CLI
 
用Tornado开发RESTful API运用
用Tornado开发RESTful API运用用Tornado开发RESTful API运用
用Tornado开发RESTful API运用
 
Masterclass Advanced Usage of the AWS CLI
Masterclass Advanced Usage of the AWS CLIMasterclass Advanced Usage of the AWS CLI
Masterclass Advanced Usage of the AWS CLI
 
The Coolest Symfony Components you’ve never heard of - DrupalCon 2017
The Coolest Symfony Components you’ve never heard of - DrupalCon 2017The Coolest Symfony Components you’ve never heard of - DrupalCon 2017
The Coolest Symfony Components you’ve never heard of - DrupalCon 2017
 
(DEV301) Advanced Usage of the AWS CLI | AWS re:Invent 2014
(DEV301) Advanced Usage of the AWS CLI | AWS re:Invent 2014(DEV301) Advanced Usage of the AWS CLI | AWS re:Invent 2014
(DEV301) Advanced Usage of the AWS CLI | AWS re:Invent 2014
 
Power shell examples_v4
Power shell examples_v4Power shell examples_v4
Power shell examples_v4
 
Baking in the cloud with packer and puppet
Baking in the cloud with packer and puppetBaking in the cloud with packer and puppet
Baking in the cloud with packer and puppet
 
Usecase examples of Packer
Usecase examples of Packer Usecase examples of Packer
Usecase examples of Packer
 
Ruby conf 2011, Create your own rails framework
Ruby conf 2011, Create your own rails frameworkRuby conf 2011, Create your own rails framework
Ruby conf 2011, Create your own rails framework
 
Phinx talk
Phinx talkPhinx talk
Phinx talk
 

Viewers also liked

Ubuntu Eco Hostal
Ubuntu Eco HostalUbuntu Eco Hostal
Ubuntu Eco Hostal
Ubuntu Eco Hostal
 
A tecnologia fotovoltaica, novos negócios e novos desafios para as concession...
A tecnologia fotovoltaica, novos negócios e novos desafios para as concession...A tecnologia fotovoltaica, novos negócios e novos desafios para as concession...
A tecnologia fotovoltaica, novos negócios e novos desafios para as concession...
Gilberto De Martino Jannuzzi
 
Un largo viaje pero al fin llegue!!!
Un largo viaje pero al fin llegue!!!Un largo viaje pero al fin llegue!!!
Un largo viaje pero al fin llegue!!!
The kiss 3Bach
 
Caminossss
CaminossssCaminossss
Caminossss
The kiss 3Bach
 
August 10 presentation
August 10 presentationAugust 10 presentation
August 10 presentation
TaZrina AlraZi RaiNy
 
The Product
The ProductThe Product
The Product
Alexandre McCormack
 
Shooting schedule
Shooting scheduleShooting schedule
Shooting schedule
edabrowskamedia
 
Chapter 1. my friends
Chapter 1. my friendsChapter 1. my friends
Chapter 1. my friends
The Language Centre, La Garita
 
Simplifique su trabajo con un único sistema para la gestión de su empresa
Simplifique su trabajo con un único sistema para la gestión de su empresaSimplifique su trabajo con un único sistema para la gestión de su empresa
Simplifique su trabajo con un único sistema para la gestión de su empresa
SAP Latinoamérica
 
The role of a Tech Lead at AXA France
The role of a Tech Lead at AXA FranceThe role of a Tech Lead at AXA France
The role of a Tech Lead at AXA France
AXA en France
 

Viewers also liked (10)

Ubuntu Eco Hostal
Ubuntu Eco HostalUbuntu Eco Hostal
Ubuntu Eco Hostal
 
A tecnologia fotovoltaica, novos negócios e novos desafios para as concession...
A tecnologia fotovoltaica, novos negócios e novos desafios para as concession...A tecnologia fotovoltaica, novos negócios e novos desafios para as concession...
A tecnologia fotovoltaica, novos negócios e novos desafios para as concession...
 
Un largo viaje pero al fin llegue!!!
Un largo viaje pero al fin llegue!!!Un largo viaje pero al fin llegue!!!
Un largo viaje pero al fin llegue!!!
 
Caminossss
CaminossssCaminossss
Caminossss
 
August 10 presentation
August 10 presentationAugust 10 presentation
August 10 presentation
 
The Product
The ProductThe Product
The Product
 
Shooting schedule
Shooting scheduleShooting schedule
Shooting schedule
 
Chapter 1. my friends
Chapter 1. my friendsChapter 1. my friends
Chapter 1. my friends
 
Simplifique su trabajo con un único sistema para la gestión de su empresa
Simplifique su trabajo con un único sistema para la gestión de su empresaSimplifique su trabajo con un único sistema para la gestión de su empresa
Simplifique su trabajo con un único sistema para la gestión de su empresa
 
The role of a Tech Lead at AXA France
The role of a Tech Lead at AXA FranceThe role of a Tech Lead at AXA France
The role of a Tech Lead at AXA France
 

Similar to CarrieWaveについてざっくり解説

Keeping the frontend under control with Symfony and Webpack
Keeping the frontend under control with Symfony and WebpackKeeping the frontend under control with Symfony and Webpack
Keeping the frontend under control with Symfony and Webpack
Ignacio Martín
 
20130528 solution linux_frousseau_nopain_webdev
20130528 solution linux_frousseau_nopain_webdev20130528 solution linux_frousseau_nopain_webdev
20130528 solution linux_frousseau_nopain_webdev
Frank Rousseau
 
Heroku pop-behind-the-sense
Heroku pop-behind-the-senseHeroku pop-behind-the-sense
Heroku pop-behind-the-sense
Ben Lin
 
Riak with Rails
Riak with RailsRiak with Rails
Riak with Rails
Sean Cribbs
 
Working With a Real-World Dataset in Neo4j: Import and Modeling
Working With a Real-World Dataset in Neo4j: Import and ModelingWorking With a Real-World Dataset in Neo4j: Import and Modeling
Working With a Real-World Dataset in Neo4j: Import and Modeling
Neo4j
 
DevOps Workflow: A Tutorial on Linux Containers
DevOps Workflow: A Tutorial on Linux ContainersDevOps Workflow: A Tutorial on Linux Containers
DevOps Workflow: A Tutorial on Linux Containers
inside-BigData.com
 
WCLA12 JavaScript
WCLA12 JavaScriptWCLA12 JavaScript
WCLA12 JavaScript
Jeffrey Zinn
 
TLS303 How to Deploy Python Applications on AWS Elastic Beanstalk - AWS re:In...
TLS303 How to Deploy Python Applications on AWS Elastic Beanstalk - AWS re:In...TLS303 How to Deploy Python Applications on AWS Elastic Beanstalk - AWS re:In...
TLS303 How to Deploy Python Applications on AWS Elastic Beanstalk - AWS re:In...
Amazon Web Services
 
Vue routing tutorial getting started with vue router
Vue routing tutorial getting started with vue routerVue routing tutorial getting started with vue router
Vue routing tutorial getting started with vue router
Katy Slemon
 
Django + Vue, JavaScript de 3ª generación para modernizar Django
Django + Vue, JavaScript de 3ª generación para modernizar DjangoDjango + Vue, JavaScript de 3ª generación para modernizar Django
Django + Vue, JavaScript de 3ª generación para modernizar Django
Javier Abadía
 
SproutCore and the Future of Web Apps
SproutCore and the Future of Web AppsSproutCore and the Future of Web Apps
SproutCore and the Future of Web Apps
Mike Subelsky
 
Getting started with rails active storage wae
Getting started with rails active storage waeGetting started with rails active storage wae
Getting started with rails active storage wae
Bishal Khanal
 
Behind the scenes of Scaleway Functions : when Kubernetes meets our products
Behind the scenes of Scaleway Functions : when Kubernetes meets our productsBehind the scenes of Scaleway Functions : when Kubernetes meets our products
Behind the scenes of Scaleway Functions : when Kubernetes meets our products
Scaleway
 
Heat up your stack
Heat up your stackHeat up your stack
Heat up your stack
Rico Lin
 
Maxim Salnikov - Service Worker: taking the best from the past experience for...
Maxim Salnikov - Service Worker: taking the best from the past experience for...Maxim Salnikov - Service Worker: taking the best from the past experience for...
Maxim Salnikov - Service Worker: taking the best from the past experience for...
Codemotion
 
Complex Made Simple: Sleep Better with TorqueBox
Complex Made Simple: Sleep Better with TorqueBoxComplex Made Simple: Sleep Better with TorqueBox
Complex Made Simple: Sleep Better with TorqueBox
bobmcwhirter
 
Scala based Lift Framework
Scala based Lift FrameworkScala based Lift Framework
Scala based Lift Framework
vhazrati
 
Overview Of Lift Framework
Overview Of Lift FrameworkOverview Of Lift Framework
Overview Of Lift Framework
Xebia IT Architects
 
Overview of The Scala Based Lift Web Framework
Overview of The Scala Based Lift Web FrameworkOverview of The Scala Based Lift Web Framework
Overview of The Scala Based Lift Web Framework
IndicThreads
 
Using WordPress as your application stack
Using WordPress as your application stackUsing WordPress as your application stack
Using WordPress as your application stack
Paul Bearne
 

Similar to CarrieWaveについてざっくり解説 (20)

Keeping the frontend under control with Symfony and Webpack
Keeping the frontend under control with Symfony and WebpackKeeping the frontend under control with Symfony and Webpack
Keeping the frontend under control with Symfony and Webpack
 
20130528 solution linux_frousseau_nopain_webdev
20130528 solution linux_frousseau_nopain_webdev20130528 solution linux_frousseau_nopain_webdev
20130528 solution linux_frousseau_nopain_webdev
 
Heroku pop-behind-the-sense
Heroku pop-behind-the-senseHeroku pop-behind-the-sense
Heroku pop-behind-the-sense
 
Riak with Rails
Riak with RailsRiak with Rails
Riak with Rails
 
Working With a Real-World Dataset in Neo4j: Import and Modeling
Working With a Real-World Dataset in Neo4j: Import and ModelingWorking With a Real-World Dataset in Neo4j: Import and Modeling
Working With a Real-World Dataset in Neo4j: Import and Modeling
 
DevOps Workflow: A Tutorial on Linux Containers
DevOps Workflow: A Tutorial on Linux ContainersDevOps Workflow: A Tutorial on Linux Containers
DevOps Workflow: A Tutorial on Linux Containers
 
WCLA12 JavaScript
WCLA12 JavaScriptWCLA12 JavaScript
WCLA12 JavaScript
 
TLS303 How to Deploy Python Applications on AWS Elastic Beanstalk - AWS re:In...
TLS303 How to Deploy Python Applications on AWS Elastic Beanstalk - AWS re:In...TLS303 How to Deploy Python Applications on AWS Elastic Beanstalk - AWS re:In...
TLS303 How to Deploy Python Applications on AWS Elastic Beanstalk - AWS re:In...
 
Vue routing tutorial getting started with vue router
Vue routing tutorial getting started with vue routerVue routing tutorial getting started with vue router
Vue routing tutorial getting started with vue router
 
Django + Vue, JavaScript de 3ª generación para modernizar Django
Django + Vue, JavaScript de 3ª generación para modernizar DjangoDjango + Vue, JavaScript de 3ª generación para modernizar Django
Django + Vue, JavaScript de 3ª generación para modernizar Django
 
SproutCore and the Future of Web Apps
SproutCore and the Future of Web AppsSproutCore and the Future of Web Apps
SproutCore and the Future of Web Apps
 
Getting started with rails active storage wae
Getting started with rails active storage waeGetting started with rails active storage wae
Getting started with rails active storage wae
 
Behind the scenes of Scaleway Functions : when Kubernetes meets our products
Behind the scenes of Scaleway Functions : when Kubernetes meets our productsBehind the scenes of Scaleway Functions : when Kubernetes meets our products
Behind the scenes of Scaleway Functions : when Kubernetes meets our products
 
Heat up your stack
Heat up your stackHeat up your stack
Heat up your stack
 
Maxim Salnikov - Service Worker: taking the best from the past experience for...
Maxim Salnikov - Service Worker: taking the best from the past experience for...Maxim Salnikov - Service Worker: taking the best from the past experience for...
Maxim Salnikov - Service Worker: taking the best from the past experience for...
 
Complex Made Simple: Sleep Better with TorqueBox
Complex Made Simple: Sleep Better with TorqueBoxComplex Made Simple: Sleep Better with TorqueBox
Complex Made Simple: Sleep Better with TorqueBox
 
Scala based Lift Framework
Scala based Lift FrameworkScala based Lift Framework
Scala based Lift Framework
 
Overview Of Lift Framework
Overview Of Lift FrameworkOverview Of Lift Framework
Overview Of Lift Framework
 
Overview of The Scala Based Lift Web Framework
Overview of The Scala Based Lift Web FrameworkOverview of The Scala Based Lift Web Framework
Overview of The Scala Based Lift Web Framework
 
Using WordPress as your application stack
Using WordPress as your application stackUsing WordPress as your application stack
Using WordPress as your application stack
 

More from ota42y

なぜか技術書典5で 3サークルの運営を同時にやった話
なぜか技術書典5で 3サークルの運営を同時にやった話なぜか技術書典5で 3サークルの運営を同時にやった話
なぜか技術書典5で 3サークルの運営を同時にやった話
ota42y
 
なぜか技術書典5で 3サークルの運営をやってた話
なぜか技術書典5で 3サークルの運営をやってた話なぜか技術書典5で 3サークルの運営をやってた話
なぜか技術書典5で 3サークルの運営をやってた話
ota42y
 
マイクロサービスにおける 結果整合性との戦い
マイクロサービスにおける 結果整合性との戦いマイクロサービスにおける 結果整合性との戦い
マイクロサービスにおける 結果整合性との戦い
ota42y
 
Rails上でのpub/sub イベントハンドラの扱い
Rails上でのpub/sub イベントハンドラの扱いRails上でのpub/sub イベントハンドラの扱い
Rails上でのpub/sub イベントハンドラの扱い
ota42y
 
goroutineはどうやって動いているのか
goroutineはどうやって動いているのかgoroutineはどうやって動いているのか
goroutineはどうやって動いているのか
ota42y
 
bootsnapはどれくらい早くなるのか
bootsnapはどれくらい早くなるのかbootsnapはどれくらい早くなるのか
bootsnapはどれくらい早くなるのか
ota42y
 
Microservices Architecture の利点と欠点
Microservices Architecture の利点と欠点Microservices Architecture の利点と欠点
Microservices Architecture の利点と欠点
ota42y
 
マイクロサービスにおける 非同期アーキテクチャ
マイクロサービスにおける非同期アーキテクチャマイクロサービスにおける非同期アーキテクチャ
マイクロサービスにおける 非同期アーキテクチャ
ota42y
 
ruby-ffiについてざっくり解説
ruby-ffiについてざっくり解説ruby-ffiについてざっくり解説
ruby-ffiについてざっくり解説
ota42y
 
FiNCでのOSSとのつきあい方
FiNCでのOSSとのつきあい方FiNCでのOSSとのつきあい方
FiNCでのOSSとのつきあい方
ota42y
 
prmdのドキュメントが読みやすくなる話
prmdのドキュメントが読みやすくなる話prmdのドキュメントが読みやすくなる話
prmdのドキュメントが読みやすくなる話
ota42y
 
身近なサイバー攻撃から身を守る
身近なサイバー攻撃から身を守る身近なサイバー攻撃から身を守る
身近なサイバー攻撃から身を守る
ota42y
 
HCI分野の紹介と最新研究
HCI分野の紹介と最新研究HCI分野の紹介と最新研究
HCI分野の紹介と最新研究
ota42y
 

More from ota42y (13)

なぜか技術書典5で 3サークルの運営を同時にやった話
なぜか技術書典5で 3サークルの運営を同時にやった話なぜか技術書典5で 3サークルの運営を同時にやった話
なぜか技術書典5で 3サークルの運営を同時にやった話
 
なぜか技術書典5で 3サークルの運営をやってた話
なぜか技術書典5で 3サークルの運営をやってた話なぜか技術書典5で 3サークルの運営をやってた話
なぜか技術書典5で 3サークルの運営をやってた話
 
マイクロサービスにおける 結果整合性との戦い
マイクロサービスにおける 結果整合性との戦いマイクロサービスにおける 結果整合性との戦い
マイクロサービスにおける 結果整合性との戦い
 
Rails上でのpub/sub イベントハンドラの扱い
Rails上でのpub/sub イベントハンドラの扱いRails上でのpub/sub イベントハンドラの扱い
Rails上でのpub/sub イベントハンドラの扱い
 
goroutineはどうやって動いているのか
goroutineはどうやって動いているのかgoroutineはどうやって動いているのか
goroutineはどうやって動いているのか
 
bootsnapはどれくらい早くなるのか
bootsnapはどれくらい早くなるのかbootsnapはどれくらい早くなるのか
bootsnapはどれくらい早くなるのか
 
Microservices Architecture の利点と欠点
Microservices Architecture の利点と欠点Microservices Architecture の利点と欠点
Microservices Architecture の利点と欠点
 
マイクロサービスにおける 非同期アーキテクチャ
マイクロサービスにおける非同期アーキテクチャマイクロサービスにおける非同期アーキテクチャ
マイクロサービスにおける 非同期アーキテクチャ
 
ruby-ffiについてざっくり解説
ruby-ffiについてざっくり解説ruby-ffiについてざっくり解説
ruby-ffiについてざっくり解説
 
FiNCでのOSSとのつきあい方
FiNCでのOSSとのつきあい方FiNCでのOSSとのつきあい方
FiNCでのOSSとのつきあい方
 
prmdのドキュメントが読みやすくなる話
prmdのドキュメントが読みやすくなる話prmdのドキュメントが読みやすくなる話
prmdのドキュメントが読みやすくなる話
 
身近なサイバー攻撃から身を守る
身近なサイバー攻撃から身を守る身近なサイバー攻撃から身を守る
身近なサイバー攻撃から身を守る
 
HCI分野の紹介と最新研究
HCI分野の紹介と最新研究HCI分野の紹介と最新研究
HCI分野の紹介と最新研究
 

Recently uploaded

DfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributionsDfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributions
gestioneergodomus
 
Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...
IJECEIAES
 
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressionsKuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
Victor Morales
 
Question paper of renewable energy sources
Question paper of renewable energy sourcesQuestion paper of renewable energy sources
Question paper of renewable energy sources
mahammadsalmanmech
 
New techniques for characterising damage in rock slopes.pdf
New techniques for characterising damage in rock slopes.pdfNew techniques for characterising damage in rock slopes.pdf
New techniques for characterising damage in rock slopes.pdf
wisnuprabawa3
 
Embedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoringEmbedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoring
IJECEIAES
 
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
IJECEIAES
 
basic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdfbasic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdf
NidhalKahouli2
 
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
VICTOR MAESTRE RAMIREZ
 
Technical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prismsTechnical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prisms
heavyhaig
 
Swimming pool mechanical components design.pptx
Swimming pool  mechanical components design.pptxSwimming pool  mechanical components design.pptx
Swimming pool mechanical components design.pptx
yokeleetan1
 
6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)
ClaraZara1
 
International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...
gerogepatton
 
22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt
KrishnaveniKrishnara1
 
14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application
SyedAbiiAzazi1
 
Generative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of contentGenerative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of content
Hitesh Mohapatra
 
Exception Handling notes in java exception
Exception Handling notes in java exceptionException Handling notes in java exception
Exception Handling notes in java exception
Ratnakar Mikkili
 
bank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdfbank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdf
Divyam548318
 
Wearable antenna for antenna applications
Wearable antenna for antenna applicationsWearable antenna for antenna applications
Wearable antenna for antenna applications
Madhumitha Jayaram
 
PPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testingPPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testing
anoopmanoharan2
 

Recently uploaded (20)

DfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributionsDfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributions
 
Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...
 
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressionsKuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
 
Question paper of renewable energy sources
Question paper of renewable energy sourcesQuestion paper of renewable energy sources
Question paper of renewable energy sources
 
New techniques for characterising damage in rock slopes.pdf
New techniques for characterising damage in rock slopes.pdfNew techniques for characterising damage in rock slopes.pdf
New techniques for characterising damage in rock slopes.pdf
 
Embedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoringEmbedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoring
 
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
 
basic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdfbasic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdf
 
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
 
Technical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prismsTechnical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prisms
 
Swimming pool mechanical components design.pptx
Swimming pool  mechanical components design.pptxSwimming pool  mechanical components design.pptx
Swimming pool mechanical components design.pptx
 
6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)
 
International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...
 
22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt
 
14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application
 
Generative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of contentGenerative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of content
 
Exception Handling notes in java exception
Exception Handling notes in java exceptionException Handling notes in java exception
Exception Handling notes in java exception
 
bank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdfbank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdf
 
Wearable antenna for antenna applications
Wearable antenna for antenna applicationsWearable antenna for antenna applications
Wearable antenna for antenna applications
 
PPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testingPPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testing
 

CarrieWaveについてざっくり解説

  • 4. CarrierWave https://github.com/bbatsov/rubocop A simple and extremely exible way to upload les It works well with Rack based web applications Cloud services support (AWS, google...) ActiveRecord integration
  • 5. Sample Code class AvatarUploader < CarrierWave::Uploader::Base storage :file end my_file = File.open('icon.png') uploader = AvatarUploader.new uploader.store!(my_file) uploader.retrieve_from_store!('inoc.png') upload to le (icon.png) Write setting to uploader class save path, extension whitelist, convert ....
  • 6. UploadSetting class MyUploader < CarrierWave::Uploader::Base include CarrierWave::MiniMagick process resize_to_fit: [800, 800] version :thumb do process resize_to_fill: [200,200] end def extension_whitelist %w(jpg png) end storage :fog def store_dir "uploads/images" end end
  • 7. Croud services support use fog gem internally https://github.com/fog/fog support many service AWS, Google, Rackspace... CarrieWave provide generate access url method
  • 8. ActiveRecord integration Save le to database column class User < ActiveRecord::Base mount_uploader :icon, AwsUploader end u = User.first u.icon = File.open('default_icon.png') u.save! u.icon.url # https://s3.amazonaws.com/path/to/file.png u.icon_identifier # => 'default_icon.png' When save model, upload le by uploader Store the lename to column
  • 9. ActiveRecord integration CarrierWave don't store le to database Store le to folder or clound (Uploader setting) This gem store lename to database (CarrierWave call identifier ) Uploader class provide le from lename
  • 10. ActiveRecord integration class User < ActiveRecord::Base mount_uploader :icon, AwsUploader end mounter_uploader create these method def icon # return AwsUploader object end def icon=(new_file) # set file to AwsUploader end def icon_identifier # return filename end
  • 11. ActiveRecord integration class User < ActiveRecord::Base mount_uploader :icon, AwsUploader end And these save methods def store_icon! # save file using AwsUploader end def write_icon_identifier # save filename to database end
  • 12. ActiveRecord integration class User < ActiveRecord::Base mount_uploader :icon, AwsUploader end And register these callbacks after_save :"store_#{column}!" before_save :"write_#{column}_identifier"
  • 13. ActiveRecord integration class User < ActiveRecord::Base mount_uploader :icon, AwsUploader end u = User.first u.icon = File.open('default_icon.png') # call icon=(filename) method and set file to AwsUploader u.save! # Call `write_inoc_identifier` from before save callback. # Write 'default_icon.png' to inon column attribute. # (call `write_attribute(:inoc, 'default_icon.png')` # So filename will store to ActiveRecord save! method. # Call `store_icon` from after save callback # This method store file using AwsUploader
  • 14. ActiveRecord integration class User < ActiveRecord::Base mount_uploader :icon, AwsUploader end u = User.first u.icon = File.open('default_icon.png') u.save! CarrierWave generate access url from lename u.icon.url # generate stored file's url u.icon_identifier # return filename in database ('default_icon.png')
  • 15. Save le to lesystem path = ::File.expand_path(store_path, store_root) if uploader.move_to_store file.move_to(path, file_permissions, dir_permissions) else file.copy_to(path, file_permissions, dir_permissions) end We can change copy or move by uploader setting https://github.com/carrierwaveuploader/carrierwave /blob/c45699c318ca895f89fa3304204e48b5f1c411 f1/lib/carrierwave/uploader/store.rb#L53
  • 16. Save le to cloud fog_file = new_file.to_file @content_type ||= new_file.content_type @file = directory.files.create({ :body => (fog_file ? fog_file : new_file).read, :content_type => @content_type, :key => path, :public => @uploader.fog_public }.merge(@uploader.fog_attributes)) fog_file.close if fog_file && !fog_file.closed? use fog gem! https://github.com/carrierwaveuploader/carrierwave /blob/c45699c318ca895f89fa3304204e48b5f1c411 f1/lib/carrierwave/storage/fog.rb#L306