paperclip_s3du 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/README.md +4 -0
- data/lib/paperclip_s3du/application_controller.rb +14 -0
- data/lib/paperclip_s3du/s3_direct_upload.rb +17 -0
- data/lib/paperclip_s3du/s3_direct_upload_adapter.rb +15 -0
- data/lib/paperclip_s3du/s3du.rb +25 -0
- data/lib/paperclip_s3du.rb +4 -0
- data/paperclip_s3du.gemspec +13 -0
- metadata +68 -0
data/.gitignore
ADDED
data/README.md
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
class ApplicationController < ActionController::Base
|
2
|
+
def self.paperclip_s3_direct_upload_for object, options = {}
|
3
|
+
only = options[:only] || [:create, :update]
|
4
|
+
|
5
|
+
before_filter :only => only do |controller|
|
6
|
+
param = options[:param] || :file
|
7
|
+
property = options[:property] || param
|
8
|
+
|
9
|
+
if params.has_key? param
|
10
|
+
params[object][property] = Paperclip::S3DU::S3DirectUpload.new params[param]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Paperclip
|
2
|
+
module S3DU
|
3
|
+
class S3DirectUpload
|
4
|
+
attr_reader :path, :size, :content_type
|
5
|
+
|
6
|
+
def initialize hash = {}
|
7
|
+
@path = hash[:file_path]
|
8
|
+
@size = hash[:file_size]
|
9
|
+
@content_type = hash[:content_type]
|
10
|
+
end
|
11
|
+
|
12
|
+
def original_filename
|
13
|
+
File.basename @path
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Paperclip
|
2
|
+
module S3DU
|
3
|
+
class S3DirectUploadAdapter < Paperclip::AbstractAdapter
|
4
|
+
delegate :path, :original_filename, :content_type, :size, :to => :@target
|
5
|
+
|
6
|
+
def initialize(target)
|
7
|
+
@target = target
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
Paperclip.io_adapters.register Paperclip::S3DU::S3DirectUploadAdapter do |target|
|
14
|
+
target.is_a? Paperclip::S3DU::S3DirectUpload
|
15
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Paperclip
|
2
|
+
module Storage
|
3
|
+
module S3du
|
4
|
+
include S3
|
5
|
+
|
6
|
+
def self.extended base
|
7
|
+
S3.extended base
|
8
|
+
end
|
9
|
+
|
10
|
+
def flush_writes #:nodoc:
|
11
|
+
@queued_for_write.each do |style, file|
|
12
|
+
if file.is_a? Paperclip::S3DU::S3DirectUploadAdapter
|
13
|
+
source = s3_bucket.objects[file.path]
|
14
|
+
destiny = s3_object(style)
|
15
|
+
source.move_to(destiny) if source.exists?
|
16
|
+
|
17
|
+
@queued_for_write.delete style
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
super
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'paperclip_s3du'
|
3
|
+
s.version = '0.0.1'
|
4
|
+
s.date = '2013-03-03'
|
5
|
+
s.summary = "Already-uploaded Paperclip"
|
6
|
+
s.description = "Paperclip support for already-uploaded-in-s3 files."
|
7
|
+
s.authors = ["Guilherme Vieira"]
|
8
|
+
s.email = 'guilherme@flipstudio.net'
|
9
|
+
s.files = `git ls-files`.split("\n").sort
|
10
|
+
s.homepage = 'https://github.com/flipstudio/s3du'
|
11
|
+
|
12
|
+
s.add_dependency("paperclip", "~> 3.0")
|
13
|
+
end
|
metadata
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: paperclip_s3du
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Guilherme Vieira
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-03-03 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: paperclip
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '3.0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '3.0'
|
30
|
+
description: Paperclip support for already-uploaded-in-s3 files.
|
31
|
+
email: guilherme@flipstudio.net
|
32
|
+
executables: []
|
33
|
+
extensions: []
|
34
|
+
extra_rdoc_files: []
|
35
|
+
files:
|
36
|
+
- .gitignore
|
37
|
+
- README.md
|
38
|
+
- lib/paperclip_s3du.rb
|
39
|
+
- lib/paperclip_s3du/application_controller.rb
|
40
|
+
- lib/paperclip_s3du/s3_direct_upload.rb
|
41
|
+
- lib/paperclip_s3du/s3_direct_upload_adapter.rb
|
42
|
+
- lib/paperclip_s3du/s3du.rb
|
43
|
+
- paperclip_s3du.gemspec
|
44
|
+
homepage: https://github.com/flipstudio/s3du
|
45
|
+
licenses: []
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options: []
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ! '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
requirements: []
|
63
|
+
rubyforge_project:
|
64
|
+
rubygems_version: 1.8.19
|
65
|
+
signing_key:
|
66
|
+
specification_version: 3
|
67
|
+
summary: Already-uploaded Paperclip
|
68
|
+
test_files: []
|