carrierwave-base64 2.8.0 → 2.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +9 -0
- data/.travis.yml +8 -4
- data/CHANGELOG.md +8 -0
- data/README.md +2 -5
- data/Rakefile +0 -7
- data/carrierwave-base64.gemspec +4 -4
- data/lib/carrierwave/base64/adapter.rb +9 -2
- data/lib/carrierwave/base64/base64_string_io.rb +2 -3
- data/lib/carrierwave/base64/railtie.rb +1 -2
- data/lib/carrierwave/base64/version.rb +1 -1
- data/spec/adapter_spec.rb +19 -0
- metadata +15 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dcc0254f7258899a78ff178e32c60221aea32cf3551a1dc0702ff1675645024b
|
4
|
+
data.tar.gz: dc0f4f9de01fe428086ac3a3289ae808e53c2a0f80713cee51b8ef177ad542d4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7e9df88c09c107a39403c969dedd523e7bcd9a152bdcb548ee3250ea63b4e8498b80a33a52903f66530f4ba95bc61c3b63081de7c08e64f62779613cc9ff486c
|
7
|
+
data.tar.gz: d104d6d00b5ee4b3772dd696f9136c0d3335aa460d3fd8543fa484050c22817a1189b21d731a748960f14fbf550c5b060f8e353c137017cda5377be19811a215
|
data/.rubocop.yml
CHANGED
data/.travis.yml
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
language: ruby
|
2
2
|
|
3
3
|
rvm:
|
4
|
-
- 2.
|
5
|
-
- 2.
|
6
|
-
- 2.
|
7
|
-
- 2.
|
4
|
+
- 2.4.9
|
5
|
+
- 2.5.7
|
6
|
+
- 2.6.5
|
7
|
+
- 2.7.0
|
8
8
|
- ruby-head
|
9
9
|
- jruby-head
|
10
10
|
|
@@ -18,6 +18,10 @@ gemfile:
|
|
18
18
|
|
19
19
|
sudo: false
|
20
20
|
|
21
|
+
before_install:
|
22
|
+
- gem update --system
|
23
|
+
- gem update bundler
|
24
|
+
|
21
25
|
script:
|
22
26
|
- bundle exec rspec
|
23
27
|
- bundle exec rubocop
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
# carrierwave-base64 changelog
|
2
2
|
|
3
|
+
## 2.10.0
|
4
|
+
|
5
|
+
- Allow `mount_base64_uploader` to take a block as an argument (#83, @shuuuuun)
|
6
|
+
|
7
|
+
## 2.9.0
|
8
|
+
|
9
|
+
- Mimemagic gem is replaced with Marcel (#87, @oakbow)
|
10
|
+
|
3
11
|
## 2.8.0
|
4
12
|
|
5
13
|
- Mime Type is now detected from file contents, falling back to the type, specified by the user. (#73, @justisb)
|
data/README.md
CHANGED
@@ -3,7 +3,6 @@
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/carrierwave-base64.svg)](http://badge.fury.io/rb/carrierwave-base64)
|
4
4
|
[![Build Status](https://travis-ci.org/y9v/carrierwave-base64.svg?branch=master)](https://travis-ci.org/y9v/carrierwave-base64)
|
5
5
|
[![Code Climate](https://codeclimate.com/github/y9v/carrierwave-base64/badges/gpa.svg)](https://codeclimate.com/github/y9v/carrierwave-base64)
|
6
|
-
[![Inch CI](https://inch-ci.org/github/y9v/carrierwave-base64.svg?branch=master)](https://inch-ci.org/github/y9v/carrierwave-base64)
|
7
6
|
|
8
7
|
Upload files encoded as base64 to carrierwave.
|
9
8
|
|
@@ -33,7 +32,7 @@ Mount the uploader to your model:
|
|
33
32
|
mount_base64_uploader :image, ImageUploader
|
34
33
|
```
|
35
34
|
|
36
|
-
Now you can also upload files by passing an encoded base64 string to the attribute.
|
35
|
+
Now you can also upload files by passing an encoded base64 string to the attribute. This also works for normal file uploads from file fields inside an HTML form, so you can safely replace `mount_uploader` with `mount_base64_uploader` to support both file input and base64 encoded input
|
37
36
|
|
38
37
|
## Upload file extension
|
39
38
|
|
@@ -69,9 +68,7 @@ mount_base64_uploader :image, ImageUploader, file_name: -> { 'userpic' }
|
|
69
68
|
|
70
69
|
## Data format
|
71
70
|
|
72
|
-
|
73
|
-
|
74
|
-
Keep in mind, that the content type specified in this string, would be used to identified the file extension. So if you have some custom content type uploaded, don't forget to register a Mime Type for it.
|
71
|
+
File extention for the uploaded file is identified automatically based on the file contents. If it can't be identified automaticaly, it falls back to the content-type, specified in the data string.
|
75
72
|
|
76
73
|
```
|
77
74
|
data:image/jpeg;base64,(base64 encoded data)
|
data/Rakefile
CHANGED
data/carrierwave-base64.gemspec
CHANGED
@@ -19,16 +19,16 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
20
|
spec.require_paths = ['lib']
|
21
21
|
|
22
|
-
spec.add_dependency 'carrierwave', '>=
|
22
|
+
spec.add_dependency 'carrierwave', '>= 2.2.1'
|
23
23
|
spec.add_dependency 'mime-types', '~> 3.0'
|
24
|
-
spec.add_dependency '
|
24
|
+
spec.add_dependency 'marcel', '~> 1.0.0'
|
25
25
|
|
26
|
-
spec.add_development_dependency 'bundler', '~> 1
|
26
|
+
spec.add_development_dependency 'bundler', '~> 2.1'
|
27
27
|
spec.add_development_dependency 'carrierwave-mongoid'
|
28
28
|
spec.add_development_dependency 'mongoid'
|
29
29
|
spec.add_development_dependency 'pry'
|
30
30
|
spec.add_development_dependency 'rails', '~> 5'
|
31
|
-
spec.add_development_dependency 'rake', '~>
|
31
|
+
spec.add_development_dependency 'rake', '~> 12.3.3'
|
32
32
|
spec.add_development_dependency 'rspec', '~> 2.14'
|
33
33
|
spec.add_development_dependency 'rubocop'
|
34
34
|
spec.add_development_dependency 'sham_rack'
|
@@ -17,9 +17,16 @@ module Carrierwave
|
|
17
17
|
# mount_base64_uploader :image, ImageUploader,
|
18
18
|
# file_name: -> (u) { u.username }
|
19
19
|
#
|
20
|
+
# @example Mount the uploader with a block, overriding the store_dir
|
21
|
+
# mount_base64_uploader :image, ImageUploader do
|
22
|
+
# def store_dir
|
23
|
+
# 'images'
|
24
|
+
# end
|
25
|
+
# end
|
26
|
+
#
|
20
27
|
# @return [Symbol] the defined writer method name
|
21
|
-
def mount_base64_uploader(attribute, uploader_class, options = {})
|
22
|
-
mount_uploader attribute, uploader_class, options
|
28
|
+
def mount_base64_uploader(attribute, uploader_class, options = {}, &block)
|
29
|
+
mount_uploader attribute, uploader_class, options, &block
|
23
30
|
options[:file_name] ||= proc { attribute }
|
24
31
|
|
25
32
|
Carrierwave::Base64::MountingHelper.check_for_deprecations(options)
|
@@ -1,5 +1,4 @@
|
|
1
|
-
require '
|
2
|
-
require 'mimemagic/overlay'
|
1
|
+
require 'marcel'
|
3
2
|
|
4
3
|
module Carrierwave
|
5
4
|
module Base64
|
@@ -48,7 +47,7 @@ module Carrierwave
|
|
48
47
|
|
49
48
|
# Determine content type from input, with provided type as fallback
|
50
49
|
def get_file_extension(description, bytes)
|
51
|
-
detected_type =
|
50
|
+
detected_type = Marcel::Magic.by_magic(bytes)
|
52
51
|
content_type = (detected_type && detected_type.type) ||
|
53
52
|
description.split(';base64').first
|
54
53
|
mime_type = MIME::Types[content_type].last
|
data/spec/adapter_spec.rb
CHANGED
@@ -170,5 +170,24 @@ RSpec.describe Carrierwave::Base64::Adapter do
|
|
170
170
|
expect { subject.update!(username: 'new-username') }.not_to raise_error
|
171
171
|
end
|
172
172
|
end
|
173
|
+
|
174
|
+
context 'models with a block for the uploader' do
|
175
|
+
subject do
|
176
|
+
User.mount_base64_uploader(:image, uploader) do
|
177
|
+
def monkey
|
178
|
+
'blah'
|
179
|
+
end
|
180
|
+
end
|
181
|
+
User.new
|
182
|
+
end
|
183
|
+
|
184
|
+
it 'should return an instance of a subclass of CarrierWave::Uploader::Base' do
|
185
|
+
expect(subject.image).to be_a(CarrierWave::Uploader::Base)
|
186
|
+
end
|
187
|
+
|
188
|
+
it 'should apply any custom modifications' do
|
189
|
+
expect(subject.image.monkey).to eq('blah')
|
190
|
+
end
|
191
|
+
end
|
173
192
|
end
|
174
193
|
end
|
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.
|
4
|
+
version: 2.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yury Lebedev
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-03-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: carrierwave
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 2.2.1
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 2.2.1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: mime-types
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -39,33 +39,33 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '3.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: marcel
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 0.
|
47
|
+
version: 1.0.0
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 0.
|
54
|
+
version: 1.0.0
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: bundler
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '1
|
61
|
+
version: '2.1'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '1
|
68
|
+
version: '2.1'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: carrierwave-mongoid
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -128,14 +128,14 @@ dependencies:
|
|
128
128
|
requirements:
|
129
129
|
- - "~>"
|
130
130
|
- !ruby/object:Gem::Version
|
131
|
-
version:
|
131
|
+
version: 12.3.3
|
132
132
|
type: :development
|
133
133
|
prerelease: false
|
134
134
|
version_requirements: !ruby/object:Gem::Requirement
|
135
135
|
requirements:
|
136
136
|
- - "~>"
|
137
137
|
- !ruby/object:Gem::Version
|
138
|
-
version:
|
138
|
+
version: 12.3.3
|
139
139
|
- !ruby/object:Gem::Dependency
|
140
140
|
name: rspec
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
@@ -247,7 +247,7 @@ homepage: https://github.com/lebedev-yury/carrierwave-base64
|
|
247
247
|
licenses:
|
248
248
|
- MIT
|
249
249
|
metadata: {}
|
250
|
-
post_install_message:
|
250
|
+
post_install_message:
|
251
251
|
rdoc_options: []
|
252
252
|
require_paths:
|
253
253
|
- lib
|
@@ -262,9 +262,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
262
262
|
- !ruby/object:Gem::Version
|
263
263
|
version: '0'
|
264
264
|
requirements: []
|
265
|
-
|
266
|
-
|
267
|
-
signing_key:
|
265
|
+
rubygems_version: 3.1.4
|
266
|
+
signing_key:
|
268
267
|
specification_version: 4
|
269
268
|
summary: Upload images encoded as base64 to carrierwave.
|
270
269
|
test_files:
|