Upgrade to Pro — share decks privately, control downloads, hide ads and more …

TDC 2014 - Solucionando o problema de Uploads e...

TDC 2014 - Solucionando o problema de Uploads em Apps no Heroku

Rafael Macedo

August 07, 2014
Tweet

More Decks by Rafael Macedo

Other Decks in Programming

Transcript

  1. ! ! ! ! Heroku Rails AWS S3 Image Magick

    Browser ! ! ! ! Resque/Sidekiq Worker
  2. ! ! ! ! Heroku Rails AWS S3 Image Magick

    Browser ! ! ! ! Resque/Sidekiq Worker
  3. ! ! ! ! Heroku Rails AWS S3 Image Magick

    Browser ! ! ! ! Resque/Sidekiq Worker
  4. ! ! ! ! Heroku Rails AWS S3 Image Magick

    Browser ! ! ! ! Resque/Sidekiq Worker
  5. ! ! ! ! Heroku Rails AWS S3 Image Magick

    Browser ! ! ! ! Resque/Sidekiq Worker
  6. ! ! ! ! Heroku Rails AWS S3 Image Magick

    Browser ! ! ! ! Resque/Sidekiq Worker
  7. •JPG, PNG, GIF, BMP, ICO, TIFF and PDF •API simples

    de upload •Upload pelo servidor ou diretamento pelo browser
  8. {
 "public_id"=>"babtchij80xduih97me0",
 "version"=>1407375612,
 "signature"=>"00b0721d1af7fd0c69eb3bc112e89022406bd027",
 "width"=>3096,
 "height"=>4128,
 "format"=>"jpg",
 "resource_type"=>"image",
 "created_at"=>"2014-08-07T01:40:12Z",
 "bytes"=>4280618,


    "type"=>"upload",
 "etag"=>"97358d56df90e5ea49e64d76c1108533",
 "url"=>"http://res.cloudinary.com/dwqsgdejq/image/ upload/v1407375612/babtchij80xduih97me0.jpg",
 "secure_url"=>"https://res.cloudinary.com/dwqsgdejq/ image/upload/v1407375612/babtchij80xduih97me0.jpg"
 } Cloudinary::Uploader.upload(
 '/tmp/carlos-mexicano.jpg'
 )
  9. \o/

  10. # config/routes.rb
 Rails.application.routes.draw do
 devise_for :users
 resources :users, only: [:update]


    root to: 'album#show'
 mount Attachinary::Engine => '/attachinary'
 end

  11. # config/routes.rb
 Rails.application.routes.draw do
 devise_for :users
 resources :users, only: [:update]


    root to: 'album#show'
 mount Attachinary::Engine => '/attachinary'
 end

  12. # app/models/user.rb
 class User < ActiveRecord::Base
 ...
 
 has_attachment :avatar,

    accept: [:gif, :jpg, :png]
 has_attachments :photos, maximum: 10
 end
  13. <%= simple_form_for @user do |f| %>
 <%= f.attachinary_file_field :avatar %>


    <%= f.attachinary_file_field :photos %>
 
 <%= f.submit %>
 <% end %> # app/views/users/_form.html.erb
  14. /* app/assets/javascript/application.js */
 //= require jquery
 //= require cloudinary
 //=

    require attachinary
 //= require_self
 
 $(function() {
 $('.attachinary-input').attachinary();
 });
  15. <%= cl_image_tag(@photo.path, width: 160, height: 160) %> <%= cl_image_tag(@photo.path, width:

    160, height: 160,
 crop: :fit) %> <%= cl_image_tag(@photo.path, width: 160, height: 160,
 crop: :thumb, gravity: :face) %>
  16. <%= cl_image_tag(@photo.path, width: 160, height: 160) %> <%= cl_image_tag(@photo.path, width:

    160, height: 160,
 crop: :fit) %> <%= cl_image_tag(@photo.path, width: 160, height: 160,
 crop: :thumb, gravity: :face) %>
  17. $$$

  18. $35

  19. S3

  20. $7

  21. ???

  22. $7

  23. $42