carrierwave-base64 2.3.2 → 2.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +6 -0
- data/lib/carrierwave/base64/base64_string_io.rb +10 -2
- data/lib/carrierwave/base64/version.rb +1 -1
- data/spec/base64_string_io_spec.rb +11 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5bc1a39edc33de0936f042be74a0c6f93a2cac55
|
4
|
+
data.tar.gz: 9935e027ef2bed8357b96bf3bd564d0ed5539134
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2916598308787dffa654be574d6f7d5cd3ef8685b5f3c4408aaa8867e14107f81c2ed6b25f2d0e8381d848f060e0140332810a2b5864dd59b922d275c3ce5307
|
7
|
+
data.tar.gz: cefdd00be933111e828805801830ece26bfe1263a1128b8dbcaf0ffd9acb8767442acd45292556ddd8f2731e6ba8433b4fd0a7a9949b73268e58fa767b4ac16b
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# carrierwave-base64 changelog
|
2
2
|
|
3
|
+
## 2.3.3
|
4
|
+
|
5
|
+
- Added proc support for the `:file_name` option for the `mount_base64_uploader` method. (credits to @hendricius)
|
6
|
+
|
3
7
|
## 2.3.0
|
4
8
|
|
5
9
|
- Added `:file_name` option for `mount_base64_uploader` method. All base64 uploads for this attribute will use the given filename for the stored file. The `:file_name` option should not contain the file extention (it will be taken from the content type of base64 string). (@HarenBroog, thanks for the idea)
|
data/README.md
CHANGED
@@ -42,6 +42,12 @@ To set the file name for the uploaded files, use the `:file_name` option (withou
|
|
42
42
|
mount_base64_uploader :image, ImageUploader, file_name: 'userpic'
|
43
43
|
```
|
44
44
|
|
45
|
+
You can also pass a Proc for the file-name to allow dynamic filenames.
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
mount_base64_uploader :image, ImageUploader, file_name: -> { "file-#{DateTime.now.to_i}" }
|
49
|
+
```
|
50
|
+
|
45
51
|
## Data format
|
46
52
|
|
47
53
|
The string with the encoded data, should be prefixed with Data URI scheme format:
|
@@ -5,13 +5,13 @@ module Carrierwave
|
|
5
5
|
|
6
6
|
attr_accessor :file_format, :file_name
|
7
7
|
|
8
|
-
def initialize(encoded_file,
|
8
|
+
def initialize(encoded_file, file_name_method_or_string)
|
9
9
|
description, encoded_bytes = encoded_file.split(',')
|
10
10
|
|
11
11
|
raise ArgumentError unless encoded_bytes
|
12
12
|
raise ArgumentError if encoded_bytes.eql?('(null)')
|
13
13
|
|
14
|
-
@file_name =
|
14
|
+
@file_name = extract_file_name(file_name_method_or_string)
|
15
15
|
@file_format = get_file_format description
|
16
16
|
bytes = ::Base64.decode64 encoded_bytes
|
17
17
|
|
@@ -28,6 +28,14 @@ module Carrierwave
|
|
28
28
|
regex = /([a-z0-9]+);base64\z/
|
29
29
|
regex.match(description).try(:[], 1)
|
30
30
|
end
|
31
|
+
|
32
|
+
def extract_file_name(method_or_string)
|
33
|
+
if method_or_string.is_a?(Proc)
|
34
|
+
method_or_string.call
|
35
|
+
else
|
36
|
+
method_or_string
|
37
|
+
end
|
38
|
+
end
|
31
39
|
end
|
32
40
|
end
|
33
41
|
end
|
@@ -16,6 +16,17 @@ RSpec.describe Carrierwave::Base64::Base64StringIO do
|
|
16
16
|
it 'should respond to :original_filename' do
|
17
17
|
expect(subject.original_filename).to eql("file.#{file_format}")
|
18
18
|
end
|
19
|
+
|
20
|
+
it 'calls a function that returns the file_name' do
|
21
|
+
method = -> { 'file-name-through-method' }
|
22
|
+
model = described_class.new data, method
|
23
|
+
expect(model.file_name).to eql('file-name-through-method')
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'accepts a string as the file name as well' do
|
27
|
+
model = described_class.new data, 'string-file-name'
|
28
|
+
expect(model.file_name).to eql('string-file-name')
|
29
|
+
end
|
19
30
|
end
|
20
31
|
end
|
21
32
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: carrierwave-base64
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.3.
|
4
|
+
version: 2.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yury Lebedev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-11-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: carrierwave
|
@@ -186,7 +186,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
186
186
|
version: '0'
|
187
187
|
requirements: []
|
188
188
|
rubyforge_project:
|
189
|
-
rubygems_version: 2.5.
|
189
|
+
rubygems_version: 2.5.2
|
190
190
|
signing_key:
|
191
191
|
specification_version: 4
|
192
192
|
summary: Upload images encoded as base64 to carrierwave.
|