carrierwave-base64-storage 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
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,58 @@
1
+ Carrierwave Base64 Storage
2
+ ==========================
3
+
4
+ This is the storage for Carrierwave that serializes the file and saves it into
5
+ the field the uploader was mounted on.
6
+
7
+
8
+ Installation
9
+ ------------
10
+
11
+ gem 'carrierwave-base64-storage'
12
+
13
+
14
+ Usage
15
+ -----
16
+
17
+ In your uploader specify the storage:
18
+
19
+ class AvatarUploader < CarrierWave::Uploader::Base
20
+ storage :base64
21
+ end
22
+
23
+ When you mount the uploader on a `field`, it uses `field_data` attribute
24
+ on the model to store the actual data, and so make sure the field exists
25
+ in your storage.
26
+
27
+ Example for the active record:
28
+
29
+ class User < ActiveRecord::Base
30
+ mount_uploader :avatar, AvatarUploader
31
+ end
32
+
33
+ (Will be using `avatar_data` for the actual data and the content type.)
34
+
35
+
36
+ License
37
+ -------
38
+
39
+ Copyright (c) 2008-2012 Aleksey Gureiev
40
+
41
+ Permission is hereby granted, free of charge, to any person obtaining a
42
+ copy of this software and associated documentation files (the
43
+ "Software"), to deal in the Software without restriction, including
44
+ without limitation the rights to use, copy, modify, merge, publish,
45
+ distribute, sublicense, and/or sell copies of the Software, and to
46
+ permit persons to whom the Software is furnished to do so, subject to
47
+ the following conditions:
48
+
49
+ The above copyright notice and this permission notice shall be included
50
+ in all copies or substantial portions of the Software.
51
+
52
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
53
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
54
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
55
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
56
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
57
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
58
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,5 @@
1
+ module CarrierWave
2
+ module Storage
3
+ autoload :Base64, 'carrierwave/storage/base64'
4
+ end
5
+ end
@@ -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
+
@@ -0,0 +1,8 @@
1
+ module CarrierWave
2
+ module Storage
3
+ module Base64Version
4
+ VERSION = '1.0.0'
5
+ end
6
+ end
7
+ end
8
+
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: carrierwave-base64-storage
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Aleksey Gureiev
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-07 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: carrierwave
16
+ requirement: &70103547176760 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70103547176760
25
+ description: Places a serialized file into a field as a Base64 string and returns
26
+ the data-url for it
27
+ email:
28
+ - spyromus@noizeramp.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - lib/carrierwave/storage/base64.rb
34
+ - lib/carrierwave/storage/base64_version.rb
35
+ - lib/carrierwave-base64-storage.rb
36
+ - LICENSE
37
+ - README.md
38
+ homepage: http://github.com/alg/carrierwave-base64-storage
39
+ licenses: []
40
+ post_install_message:
41
+ rdoc_options: []
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ! '>='
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: 1.3.6
56
+ requirements: []
57
+ rubyforge_project:
58
+ rubygems_version: 1.8.10
59
+ signing_key:
60
+ specification_version: 3
61
+ summary: Base64 based storage engine for your CarrierWave uploads
62
+ test_files: []