mwilliams-carrierwave-base64-storage 1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +22 -0
- data/README.md +5 -0
- data/lib/carrierwave-base64-storage.rb +5 -0
- data/lib/carrierwave/storage/base64.rb +68 -0
- data/lib/carrierwave/storage/base64_version.rb +8 -0
- metadata +84 -0
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2011 Aleksey Gureiev and ProjectProject Pty Ltd.
|
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,68 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'base64'
|
3
|
+
|
4
|
+
module CarrierWave
|
5
|
+
module Storage
|
6
|
+
class Base64 < Abstract
|
7
|
+
|
8
|
+
class File
|
9
|
+
def initialize(uploader)
|
10
|
+
@uploader = uploader
|
11
|
+
end
|
12
|
+
|
13
|
+
def path
|
14
|
+
nil
|
15
|
+
end
|
16
|
+
|
17
|
+
def read
|
18
|
+
d = self.data[:data]
|
19
|
+
d ? ::Base64.decode64(d) : nil
|
20
|
+
end
|
21
|
+
|
22
|
+
def delete
|
23
|
+
# TODO clear the field?
|
24
|
+
end
|
25
|
+
|
26
|
+
def url
|
27
|
+
d = self.data[:data]
|
28
|
+
d ? "data:#{self.data[:content_type] || 'image/png'};base64,#{d}" : nil
|
29
|
+
end
|
30
|
+
|
31
|
+
def store(file)
|
32
|
+
self.data = {
|
33
|
+
:data => "#{::Base64.encode64(file.read)}",
|
34
|
+
:content_type => file.content_type }
|
35
|
+
end
|
36
|
+
|
37
|
+
def content_type
|
38
|
+
self.data[:content_type]
|
39
|
+
end
|
40
|
+
|
41
|
+
def data=(v)
|
42
|
+
m, f = @uploader.model, @uploader.mounted_as
|
43
|
+
updated = m.send("#{f}_data") != v
|
44
|
+
if updated
|
45
|
+
m.send("#{f}_data=", v)
|
46
|
+
m.save
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def data
|
51
|
+
@uploader.model.send("#{@uploader.mounted_as}_data") || {}
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def store!(file)
|
56
|
+
f = CarrierWave::Storage::Base64::File.new(uploader)
|
57
|
+
f.store(file)
|
58
|
+
f
|
59
|
+
end
|
60
|
+
|
61
|
+
def retrieve!(identifier)
|
62
|
+
CarrierWave::Storage::Base64::File.new(uploader)
|
63
|
+
end
|
64
|
+
|
65
|
+
end # S3
|
66
|
+
end # Storage
|
67
|
+
end # CarrierWave
|
68
|
+
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mwilliams-carrierwave-base64-storage
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 15
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
version: "1.0"
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Aleksey Gureiev
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2012-03-06 00:00:00 Z
|
18
|
+
dependencies:
|
19
|
+
- !ruby/object:Gem::Dependency
|
20
|
+
name: carrierwave
|
21
|
+
prerelease: false
|
22
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
23
|
+
none: false
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
hash: 3
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
version: "0"
|
31
|
+
type: :runtime
|
32
|
+
version_requirements: *id001
|
33
|
+
description: Places a serialized file into a field as a Base64 string and returns the data-url for it
|
34
|
+
email:
|
35
|
+
- spyromus@noizeramp.com
|
36
|
+
executables: []
|
37
|
+
|
38
|
+
extensions: []
|
39
|
+
|
40
|
+
extra_rdoc_files: []
|
41
|
+
|
42
|
+
files:
|
43
|
+
- lib/carrierwave/storage/base64.rb
|
44
|
+
- lib/carrierwave/storage/base64_version.rb
|
45
|
+
- lib/carrierwave-base64-storage.rb
|
46
|
+
- LICENSE
|
47
|
+
- README.md
|
48
|
+
homepage: http://github.com/alg/carrierwave-base64-storage
|
49
|
+
licenses: []
|
50
|
+
|
51
|
+
post_install_message:
|
52
|
+
rdoc_options: []
|
53
|
+
|
54
|
+
require_paths:
|
55
|
+
- lib
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
hash: 3
|
62
|
+
segments:
|
63
|
+
- 0
|
64
|
+
version: "0"
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
hash: 23
|
71
|
+
segments:
|
72
|
+
- 1
|
73
|
+
- 3
|
74
|
+
- 6
|
75
|
+
version: 1.3.6
|
76
|
+
requirements: []
|
77
|
+
|
78
|
+
rubyforge_project:
|
79
|
+
rubygems_version: 1.8.15
|
80
|
+
signing_key:
|
81
|
+
specification_version: 3
|
82
|
+
summary: Base64 based storage engine for your CarrierWave uploads
|
83
|
+
test_files: []
|
84
|
+
|