blobsterix_carrierwave 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +20 -0
- data/CHANGELOG.txt +9 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +93 -0
- data/Rakefile +2 -0
- data/bin/blobsterix_uploader +23 -0
- data/blobsterix_carrierwave.gemspec +20 -0
- data/config/uploader_template.rb +40 -0
- data/lib/blobsterix_carrierwave/blobsterix_adhoc_transforms.rb +103 -0
- data/lib/blobsterix_carrierwave/blobsterix_carrierwave.rb +84 -0
- data/lib/blobsterix_carrierwave/blobsterix_storage.rb +95 -0
- data/lib/blobsterix_carrierwave/blobsterix_transforms.rb +45 -0
- data/lib/blobsterix_carrierwave/blobsterix_uploader.rb +86 -0
- data/lib/blobsterix_carrierwave/version.rb +4 -0
- data/lib/blobsterix_carrierwave.rb +22 -0
- metadata +89 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8ea3e909ae2f9f7de7dede8bee31dcdffb2d2ad1
|
4
|
+
data.tar.gz: 10456d10772b34e0200757b561ad3348e7c7fa21
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 93dedde583457804200e53ffc0fe0777ae34d7a3486bb9ce010d9b096acbfa579b9e16a7c8949005c6c1bd9cad87da3c1ef43f8029ddacec778c17f5aaf4b315
|
7
|
+
data.tar.gz: 9496905c70773e445d2965eb38b36ee7a1a6abfa794b418a0648ddd96b26c54a004711b302b891b552c611fe81fb9b43d7ae14e3d0b48c0985244eaaff6dbb63
|
data/.gitignore
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
.ruby-gemset
|
19
|
+
.ruby-version
|
20
|
+
.rbenv-gemsets
|
data/CHANGELOG.txt
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 dsudmann
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
# BlobsterixCarrierwave
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'blobsterix_carrierwave'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install blobsterix_carrierwave
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Setup:
|
22
|
+
# Configuration to setup carrierwave. This is needed for everything to work
|
23
|
+
CarrierWave.configure do |config|
|
24
|
+
config.fog_credentials = {
|
25
|
+
:provider => 'AWS', # required
|
26
|
+
:aws_access_key_id => 'xxx', # required
|
27
|
+
:aws_secret_access_key => 'yyy', # required
|
28
|
+
:region => 'eu-west-1', # optional, defaults to 'us-east-1'
|
29
|
+
:host => 'blob.localhost.local', # this hast to have 3 levels so the s3 libs can split them, won't ever be used
|
30
|
+
:connection_options => {:proxy => "http://#{Pjpp.config.blobsterix_upload_host_port}" }, #need a proxy as the s3 interface uses hostnames
|
31
|
+
#won't mess with dynamic DNS, THIS IS THE REAL upload host
|
32
|
+
:endpoint => "http://blob.localhost.local" # same as host, won't ever be used
|
33
|
+
}
|
34
|
+
config.fog_directory = 'pjpp' # required, can be overridden in each uploader
|
35
|
+
config.fog_public = true # optional, defaults to true, and actually not used here anymore.
|
36
|
+
config.fog_attributes = {'Cache-Control'=>'max-age=315576000'} # optional, defaults to {}
|
37
|
+
config.delete_tmp_file_after_storage = true
|
38
|
+
config.remove_previously_stored_files_after_update = true
|
39
|
+
config.asset_host = proc do |uploader|
|
40
|
+
BlobsterixAdhocTransforms::Generator.new(:host => Pjpp.config.blobsterix_host_port, :uploader => uploader, :trafos => uploader.remote_processors)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# Simple uploader. Image is scaled to fit hight restriction, converted to png and stripped of all commentary data during upload
|
45
|
+
# Now during download it offers three version. One without any transformation which will allow blobsterix to decide what is the best content type.
|
46
|
+
# In case of images Chrome user would get webp images. The raw version restricts blobsterix to deliver the image in the same format it is saved on the server.
|
47
|
+
# And in case of the crazy version it will rotate the image and then convert to best format again since its not locked.
|
48
|
+
# The usage of the uploader is like the normal carrierwave.
|
49
|
+
class CompanyLogoUploader < BlobsterixUploader
|
50
|
+
|
51
|
+
process :resize => ["", "300"]
|
52
|
+
process :strip
|
53
|
+
process :set_format => "png"
|
54
|
+
|
55
|
+
def store_dir
|
56
|
+
"company_logos"
|
57
|
+
end
|
58
|
+
|
59
|
+
def bucket
|
60
|
+
"jobapp"
|
61
|
+
end
|
62
|
+
|
63
|
+
version :raw do
|
64
|
+
process :set_format => "raw"
|
65
|
+
end
|
66
|
+
|
67
|
+
version :crazy do
|
68
|
+
process :rotate => 25
|
69
|
+
end
|
70
|
+
|
71
|
+
def name_on_server
|
72
|
+
"#{model.id}_#{Time.new.to_i}"
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
# Since the transformations are done on the fly and not in the application during upload, the uploader also allows custom transforms that do not have to be hardcoded.
|
77
|
+
# instead of:
|
78
|
+
|
79
|
+
company_logo.raw.url
|
80
|
+
|
81
|
+
# you can do
|
82
|
+
|
83
|
+
company_logo.custom.resize(200).rotate(25).url
|
84
|
+
|
85
|
+
# this will generate the url and blobsterix will generate the image on the fly.
|
86
|
+
|
87
|
+
## Contributing
|
88
|
+
|
89
|
+
1. Fork it
|
90
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
91
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
92
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
93
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "fileutils"
|
4
|
+
puts "Blobsterix upload generator"
|
5
|
+
if ARGV.length == 0
|
6
|
+
puts "Usage: "
|
7
|
+
puts "\tblobsterix_uploader uploader_name"
|
8
|
+
exit
|
9
|
+
end
|
10
|
+
|
11
|
+
|
12
|
+
template = File.read(File.join(File.dirname(__FILE__), "../config/uploader_template.rb"))
|
13
|
+
template = template.gsub("$UploaderName", ARGV[0].capitalize)
|
14
|
+
|
15
|
+
if !File.exist?(File.join(Dir.pwd, "app/uploaders/#{ARGV[0].downcase}_uploader.rb"))
|
16
|
+
FileUtils.mkdir_p(File.join(Dir.pwd, "app/uploaders"))
|
17
|
+
File.open(File.join(Dir.pwd, "app/uploaders/#{ARGV[0].downcase}_uploader.rb"), "w+") {|f|
|
18
|
+
f.write(template)
|
19
|
+
}
|
20
|
+
puts "Generated new uploader"
|
21
|
+
else
|
22
|
+
puts "Uploader already exists"
|
23
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/blobsterix_carrierwave/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Daniel Sudmann"]
|
6
|
+
gem.email = ["suddani@googlemail.com"]
|
7
|
+
gem.description = "This gem is used to create a carrierwave binding to a blobsterix server"
|
8
|
+
gem.summary = "This gem is used to create a carrierwave binding to a blobsterix server"
|
9
|
+
gem.homepage = "http://experteer.com"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "blobsterix_carrierwave"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = BlobsterixCarrierwave::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency "carrierwave", "~> 0.9.0"
|
19
|
+
gem.add_dependency "fog" , "~> 1.3.1"
|
20
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
class $UploaderNameUploader < BlobsterixUploader
|
4
|
+
|
5
|
+
# When setting a global process it is applied when
|
6
|
+
# uploaded to a blobsterix server
|
7
|
+
#process :resize => ["", "300"]
|
8
|
+
|
9
|
+
# This sets a directory inside a bucket
|
10
|
+
# only used for cosmetic reasons
|
11
|
+
#def store_dir
|
12
|
+
# "some_dir"
|
13
|
+
#end
|
14
|
+
|
15
|
+
# This function overrides the bucket set
|
16
|
+
# in the carrierwave fog config
|
17
|
+
# only use if this uploader should use a different bucket
|
18
|
+
#def bucket
|
19
|
+
# "jobapp"
|
20
|
+
#end
|
21
|
+
|
22
|
+
# Versions work the same as in normal carrierwave
|
23
|
+
# with the difference that versions are generated
|
24
|
+
# on the server when requested and are not generated
|
25
|
+
# when uploading
|
26
|
+
#version :raw do
|
27
|
+
# process :resize => 100
|
28
|
+
# process :rotate => 25
|
29
|
+
# process :set_format => "raw"
|
30
|
+
#end
|
31
|
+
|
32
|
+
# This function is used to set the name of the file
|
33
|
+
# on the server to something else than the actual upload
|
34
|
+
# filename. So only use it when that behaviour is desired.
|
35
|
+
# Example: It can be used to generate timestamped names
|
36
|
+
# to invalidate the client cache
|
37
|
+
#def name_on_server
|
38
|
+
# "#{model.id}_#{Time.new.to_i}"
|
39
|
+
#end
|
40
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module BlobsterixAdhocTransforms
|
3
|
+
extend BlobsterixTransforms
|
4
|
+
class Generator
|
5
|
+
def initialize(options={})
|
6
|
+
# host
|
7
|
+
# bucket
|
8
|
+
# path
|
9
|
+
# trafos <- array with transform methods and
|
10
|
+
# uploader <- BlobsterixCarrierWaveUploader
|
11
|
+
@options = options || {}
|
12
|
+
@chain=[]
|
13
|
+
|
14
|
+
#init the trafos
|
15
|
+
(@options[:trafos] || []).each{|t|
|
16
|
+
c.send(t[0], t[1])
|
17
|
+
}
|
18
|
+
end
|
19
|
+
|
20
|
+
def clear_trafo
|
21
|
+
@chain = []
|
22
|
+
self
|
23
|
+
end
|
24
|
+
|
25
|
+
def set_path(path)
|
26
|
+
@options[:path] = path
|
27
|
+
self
|
28
|
+
end
|
29
|
+
|
30
|
+
def url(path=nil)
|
31
|
+
@options[:path] = path if path
|
32
|
+
"#{asset_host}#{encoded_path}"
|
33
|
+
end
|
34
|
+
|
35
|
+
def url_s3(path=nil, use_subdomain=true)
|
36
|
+
@options[:path] = path if path
|
37
|
+
|
38
|
+
"#{s3_host(use_subdomain)}#{encoded_path}"
|
39
|
+
end
|
40
|
+
|
41
|
+
def transform(encrypt=true)
|
42
|
+
trafo = @chain.map{|trafo|
|
43
|
+
"#{trafo[:method]}_#{trafo[:args]}"
|
44
|
+
}.join(",")
|
45
|
+
encrypt ? BlobsterixCarrierwave.encrypt_trafo(trafo, self) : trafo
|
46
|
+
end
|
47
|
+
|
48
|
+
def has_transform?
|
49
|
+
!@chain.empty?
|
50
|
+
end
|
51
|
+
|
52
|
+
def method_missing(method, *args)
|
53
|
+
if BlobsterixAdhocTransforms.respond_to?(method)
|
54
|
+
@chain << BlobsterixAdhocTransforms.send(method, *args)
|
55
|
+
else
|
56
|
+
#shit!
|
57
|
+
end
|
58
|
+
self
|
59
|
+
end
|
60
|
+
|
61
|
+
def uploader
|
62
|
+
@options[:uploader]
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
def version
|
67
|
+
@options[:version] || 1
|
68
|
+
end
|
69
|
+
def encoded_path
|
70
|
+
@options[:path] || ""
|
71
|
+
end
|
72
|
+
def s3_host(use_subdomain)
|
73
|
+
if (use_subdomain)
|
74
|
+
"http://#{bucket}.#{@options[:host]}/"
|
75
|
+
else
|
76
|
+
"http://#{@options[:host]}/#{bucket}/"
|
77
|
+
end
|
78
|
+
end
|
79
|
+
def asset_host
|
80
|
+
|
81
|
+
host = @options[:host] || ""
|
82
|
+
if host.respond_to? :call and @options.has_key?(:uploader)
|
83
|
+
host.call(self)
|
84
|
+
else
|
85
|
+
trafo = transform
|
86
|
+
if trafo.length > 0
|
87
|
+
"http://#{host}/blob/v#{version}/#{trafo}.#{bucket}/"
|
88
|
+
else
|
89
|
+
"http://#{host}/blob/v#{version}/#{bucket}/"
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
#"http://localhost:9000/blob/v1/#{trafo}.#{uploader.fog_directory}/"
|
94
|
+
end
|
95
|
+
def bucket()
|
96
|
+
if @options.has_key?(:uploader)
|
97
|
+
@options[:uploader].fog_directory
|
98
|
+
else
|
99
|
+
@options[:bucket] || "main"
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module Blobsterix
|
3
|
+
module CarrierWave
|
4
|
+
#crazy version stuff not needed anymore
|
5
|
+
def recreate_versions!
|
6
|
+
# Do nothing
|
7
|
+
# puts "Recreate versions"
|
8
|
+
end
|
9
|
+
|
10
|
+
def cache_versions!(new_file=nil)
|
11
|
+
# Do nothing
|
12
|
+
# puts "Cache versions"
|
13
|
+
end
|
14
|
+
|
15
|
+
def store_versions!(new_file=nil)
|
16
|
+
# Do nothing
|
17
|
+
# puts "Store versions"
|
18
|
+
end
|
19
|
+
|
20
|
+
def remove_versions!(new_file=nil)
|
21
|
+
# Do nothing
|
22
|
+
# puts "Remove versions"
|
23
|
+
end
|
24
|
+
|
25
|
+
def retrieve_versions_from_cache!(new_file=nil)
|
26
|
+
# Do nothing
|
27
|
+
# puts "retrieve_versions_from_cache: #{version_name}"
|
28
|
+
end
|
29
|
+
|
30
|
+
def retrieve_versions_from_store!(new_file=nil)
|
31
|
+
# Do nothing
|
32
|
+
# puts "retrieve_versions_from_store: #{new_file.inspect}, #{version_name}"
|
33
|
+
super(new_file)
|
34
|
+
end
|
35
|
+
|
36
|
+
def process!(new_file=nil)
|
37
|
+
# Do nothing
|
38
|
+
# puts "Doing process for #{new_file.inspect} on #{self.inspect}"
|
39
|
+
end
|
40
|
+
|
41
|
+
def remote_process!(encrypt=true)
|
42
|
+
if enable_processing
|
43
|
+
#Deactivate conditional stuff
|
44
|
+
# self.class.processors.each do |method, args, condition|
|
45
|
+
# if(condition)
|
46
|
+
# next if !(condition.respond_to?(:call) ? condition.call(self, :args => args, :method => method, :file => new_file) : self.send(condition, new_file))
|
47
|
+
# end
|
48
|
+
# puts "Do: #{method} with #{args.inspect}"
|
49
|
+
# trafos.send(method, *args)
|
50
|
+
# end
|
51
|
+
BlobsterixAdhocTransforms::Generator.new(:trafos => self.class.processors.map{|method, args, condition|[method, args]}).transform(encrypt)
|
52
|
+
else
|
53
|
+
""
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def remote_processors()
|
58
|
+
# puts "Version: #{version_name}"
|
59
|
+
if enable_processing and version_name
|
60
|
+
current_processor = self.class
|
61
|
+
remote_processor_array = []
|
62
|
+
until current_processor.parent == Object
|
63
|
+
remote_processor_array+=current_processor.processors.map{|method, args, condition|[method, args]}
|
64
|
+
current_processor = current_processor.parent
|
65
|
+
end
|
66
|
+
remote_processor_array
|
67
|
+
else
|
68
|
+
[]
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
private
|
73
|
+
#much important, very nice, wow
|
74
|
+
def full_filename(for_file)
|
75
|
+
#[remote_process!, for_file].join(".")
|
76
|
+
for_file
|
77
|
+
end
|
78
|
+
|
79
|
+
#url call somehow broken so just call it directly
|
80
|
+
# def url(options = {})
|
81
|
+
# file.url(options)
|
82
|
+
# end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module CarrierWave
|
3
|
+
module Storage
|
4
|
+
class BlobsterixStore < Fog
|
5
|
+
# From Abstract
|
6
|
+
# attr_reader :uploader
|
7
|
+
|
8
|
+
# def initialize(uploader)
|
9
|
+
# @uploader = uploader
|
10
|
+
# puts "Init BlobsterixStore"
|
11
|
+
# end
|
12
|
+
|
13
|
+
# def identifier
|
14
|
+
# uploader.filename
|
15
|
+
# end
|
16
|
+
|
17
|
+
#################
|
18
|
+
# Abstract provides stubs we must implement.
|
19
|
+
#
|
20
|
+
# Create and save a file instance to your engine.
|
21
|
+
def store!(file)
|
22
|
+
# puts "Called store: #{file.inspect} with #{uploader.processors}"
|
23
|
+
f = File.new(uploader, self, uploader.store_path)
|
24
|
+
f.store(file)
|
25
|
+
f
|
26
|
+
end
|
27
|
+
|
28
|
+
# Load and return a file instance from your engine.
|
29
|
+
def retrieve!(identifier)
|
30
|
+
# puts "Called retrieve: #{identifier.class}:#{identifier}"
|
31
|
+
File.new(uploader, self, uploader.store_path(identifier))
|
32
|
+
end
|
33
|
+
|
34
|
+
# Subclass or duck-type CarrierWave::SanitizedFile ; responsible for storing the file to your engine.
|
35
|
+
class File < Fog::File
|
36
|
+
def initialize(uploader, base, path)
|
37
|
+
@uploader, @base, @path = uploader, base, path
|
38
|
+
end
|
39
|
+
|
40
|
+
def url(options = {})
|
41
|
+
# puts "Get file url: #{options}, #{@uploader.version_name}"
|
42
|
+
u = super(options)
|
43
|
+
# puts "Url is now: #{u}"
|
44
|
+
u
|
45
|
+
end
|
46
|
+
|
47
|
+
def store(new_file)
|
48
|
+
fog_file = new_file.to_file
|
49
|
+
@content_type ||= new_file.content_type
|
50
|
+
@file = directory.files.new({
|
51
|
+
:body => fog_file ? fog_file : new_file.read,
|
52
|
+
:content_type => @content_type,
|
53
|
+
:key => path,
|
54
|
+
:public => @uploader.fog_public,
|
55
|
+
:collection => directory.files,
|
56
|
+
:connection => directory.files.connection
|
57
|
+
}.merge(@uploader.fog_attributes))
|
58
|
+
@file.metadata={"x-amz-meta-trafo" => @uploader.remote_process!(false)}
|
59
|
+
@file.save()
|
60
|
+
fog_file.close if fog_file && !fog_file.closed?
|
61
|
+
true
|
62
|
+
end
|
63
|
+
|
64
|
+
def public_url
|
65
|
+
@uploader.asset_host.url(encode_path(path))
|
66
|
+
end
|
67
|
+
|
68
|
+
def read
|
69
|
+
super()
|
70
|
+
end
|
71
|
+
def size
|
72
|
+
super()
|
73
|
+
end
|
74
|
+
def delete
|
75
|
+
super()
|
76
|
+
end
|
77
|
+
def exists?
|
78
|
+
url = BlobsterixAdhocTransforms::Generator.new(:host => @uploader.fog_credentials[:connection_options][:proxy].gsub("http://",""), :uploader => @uploader, :path => @path).url_s3(nil, false)
|
79
|
+
# puts "Check url: #{url}"
|
80
|
+
uri = URI(url)
|
81
|
+
return_code = 404
|
82
|
+
Net::HTTP.start(uri.host, uri.port) do |http|
|
83
|
+
response = http.get uri.path # Net::HTTPResponse object
|
84
|
+
response.code
|
85
|
+
end == "200"
|
86
|
+
end
|
87
|
+
# Others... ?
|
88
|
+
def process
|
89
|
+
end
|
90
|
+
|
91
|
+
end # File
|
92
|
+
|
93
|
+
end # MyEngine
|
94
|
+
end # Storage
|
95
|
+
end # CarrierWave
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module BlobsterixTransforms
|
3
|
+
def resize(args)
|
4
|
+
args=[args].flatten
|
5
|
+
width=args[0]
|
6
|
+
height=args[1]
|
7
|
+
{
|
8
|
+
:method => "resize",
|
9
|
+
:args => "#{width}x#{height}"
|
10
|
+
}
|
11
|
+
end
|
12
|
+
def resizemax(args)
|
13
|
+
args=[args].flatten
|
14
|
+
width=args[0]
|
15
|
+
height=args[1]
|
16
|
+
{
|
17
|
+
:method => "resizemax",
|
18
|
+
:args => "#{width}x#{height}"
|
19
|
+
}
|
20
|
+
end
|
21
|
+
def rotate(angle)
|
22
|
+
{
|
23
|
+
:method => "rotate",
|
24
|
+
:args => "#{angle}"
|
25
|
+
}
|
26
|
+
end
|
27
|
+
def raw_image(e)
|
28
|
+
{
|
29
|
+
:method => "raw",
|
30
|
+
:args => ""
|
31
|
+
}
|
32
|
+
end
|
33
|
+
def set_format(format, option = "")
|
34
|
+
{
|
35
|
+
:method => format,
|
36
|
+
:args => option
|
37
|
+
}
|
38
|
+
end
|
39
|
+
def strip(e)
|
40
|
+
{
|
41
|
+
:method => "strip",
|
42
|
+
:args => ""
|
43
|
+
}
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
class BlobsterixUploader < CarrierWave::Uploader::Base
|
3
|
+
|
4
|
+
include CarrierWave::MimeTypes
|
5
|
+
include Blobsterix::CarrierWave
|
6
|
+
|
7
|
+
#storage :file
|
8
|
+
storage CarrierWave::Storage::BlobsterixStore
|
9
|
+
|
10
|
+
include BlobsterixTransforms
|
11
|
+
|
12
|
+
after :store, :done_store
|
13
|
+
before :store, :before_store
|
14
|
+
|
15
|
+
def before_store obj
|
16
|
+
#puts "Start with storing"
|
17
|
+
end
|
18
|
+
def done_store obj
|
19
|
+
#puts "Done with storing"
|
20
|
+
end
|
21
|
+
|
22
|
+
# Override the directory where uploaded files will be stored.
|
23
|
+
# This is a sensible default for uploaders that are meant to be mounted:
|
24
|
+
def store_dir
|
25
|
+
#puts "Would say: uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
|
26
|
+
"images"
|
27
|
+
#"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
|
28
|
+
end
|
29
|
+
|
30
|
+
def fog_directory
|
31
|
+
bucket || super()
|
32
|
+
end
|
33
|
+
|
34
|
+
def bucket
|
35
|
+
nil
|
36
|
+
end
|
37
|
+
|
38
|
+
def custom
|
39
|
+
asset_host.set_path(path).clear_trafo
|
40
|
+
end
|
41
|
+
|
42
|
+
def filename
|
43
|
+
if original_filename.present? and respond_to?(:name_on_server)
|
44
|
+
name_on_server
|
45
|
+
else
|
46
|
+
super()
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# Provide a default URL as a default if there hasn't been a file uploaded:
|
51
|
+
# def default_url
|
52
|
+
# # For Rails 3.1+ asset pipeline compatibility:
|
53
|
+
# # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))
|
54
|
+
#
|
55
|
+
# "/images/fallback/" + [version_name, "default.png"].compact.join('_')
|
56
|
+
# end
|
57
|
+
|
58
|
+
# Process files as they are uploaded:
|
59
|
+
#process :resize => ["", "300"]
|
60
|
+
#process :rotate => 45
|
61
|
+
#
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
# Create different versions of your uploaded files:
|
66
|
+
# version :thumb do
|
67
|
+
# process :resize => [50, "50!"]
|
68
|
+
# end
|
69
|
+
|
70
|
+
# version :face do
|
71
|
+
# process :resize => [10, 10]
|
72
|
+
# end
|
73
|
+
|
74
|
+
# Add a white list of extensions which are allowed to be uploaded.
|
75
|
+
# For images you might use something like this:
|
76
|
+
# def extension_white_list
|
77
|
+
# %w(jpg jpeg gif png)
|
78
|
+
# end
|
79
|
+
|
80
|
+
# Override the filename of the uploaded files:
|
81
|
+
# Avoid using model.id or version_name here, see uploader/store.rb for details.
|
82
|
+
# def filename
|
83
|
+
# "something.jpg" if original_filename
|
84
|
+
# end
|
85
|
+
|
86
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require "blobsterix_carrierwave/version"
|
2
|
+
|
3
|
+
require "carrierwave"
|
4
|
+
require "fog"
|
5
|
+
|
6
|
+
require "blobsterix_carrierwave/blobsterix_carrierwave"
|
7
|
+
require "blobsterix_carrierwave/blobsterix_storage"
|
8
|
+
require "blobsterix_carrierwave/blobsterix_transforms"
|
9
|
+
require "blobsterix_carrierwave/blobsterix_adhoc_transforms"
|
10
|
+
require "blobsterix_carrierwave/blobsterix_uploader"
|
11
|
+
|
12
|
+
module BlobsterixCarrierwave
|
13
|
+
# Your code goes here...
|
14
|
+
def self.encrypt_trafo(trafo_string=nil, generator=nil)
|
15
|
+
@encrypt_trafo||=lambda{|t_string, generator| t_string}
|
16
|
+
trafo_string ? @encrypt_trafo.call(trafo_string, generator) : @encrypt_trafo
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.encrypt_trafo=(obj)
|
20
|
+
@encrypt_trafo=obj
|
21
|
+
end
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: blobsterix_carrierwave
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.7
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Daniel Sudmann
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-04-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: carrierwave
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.9.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.9.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: fog
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.3.1
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.3.1
|
41
|
+
description: This gem is used to create a carrierwave binding to a blobsterix server
|
42
|
+
email:
|
43
|
+
- suddani@googlemail.com
|
44
|
+
executables:
|
45
|
+
- blobsterix_uploader
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- .gitignore
|
50
|
+
- CHANGELOG.txt
|
51
|
+
- Gemfile
|
52
|
+
- LICENSE
|
53
|
+
- README.md
|
54
|
+
- Rakefile
|
55
|
+
- bin/blobsterix_uploader
|
56
|
+
- blobsterix_carrierwave.gemspec
|
57
|
+
- config/uploader_template.rb
|
58
|
+
- lib/blobsterix_carrierwave.rb
|
59
|
+
- lib/blobsterix_carrierwave/blobsterix_adhoc_transforms.rb
|
60
|
+
- lib/blobsterix_carrierwave/blobsterix_carrierwave.rb
|
61
|
+
- lib/blobsterix_carrierwave/blobsterix_storage.rb
|
62
|
+
- lib/blobsterix_carrierwave/blobsterix_transforms.rb
|
63
|
+
- lib/blobsterix_carrierwave/blobsterix_uploader.rb
|
64
|
+
- lib/blobsterix_carrierwave/version.rb
|
65
|
+
homepage: http://experteer.com
|
66
|
+
licenses: []
|
67
|
+
metadata: {}
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options: []
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - '>='
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
requirements: []
|
83
|
+
rubyforge_project:
|
84
|
+
rubygems_version: 2.0.14
|
85
|
+
signing_key:
|
86
|
+
specification_version: 4
|
87
|
+
summary: This gem is used to create a carrierwave binding to a blobsterix server
|
88
|
+
test_files: []
|
89
|
+
has_rdoc:
|