carrierwave-base64 2.6.0 → 2.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: fb281b2683a576956173494d155b372c985499a8
4
- data.tar.gz: e28479d1490ba1a00ce8e20a862f9636fa1f78f5
2
+ SHA256:
3
+ metadata.gz: 3af16036cb1f1a6f3ae6ffce52db973a32c09c76287cde31036bed14b9989d3f
4
+ data.tar.gz: 62500de72742bb64cae9f3839124892f33463044c554f245b256868262c64e5d
5
5
  SHA512:
6
- metadata.gz: f102337cef6625d4ec0ea0e281c1d4e0ff57af69d9778d0b8073e4379f1fcea9ef2212002683f92643b83b7ddd03a3bf1e8c18aec92908485a709e6beb1b1098
7
- data.tar.gz: 7e18c8cc657eebcb475caf0b6e0c5a541ada043ebb09b5506354b49b0ae427ba5f0ba1c4055c2970ecc1080148852d77c6cc65a13df11759fe9199b33e899279
6
+ metadata.gz: f7e8b717582744821f8bd91437ced8f9fe7e794c6c9821e613a3b1c4eb4f33f5e4774b15428a74ddf8e1080143a9444b958776e7c8c156c2004bb97767e84e60
7
+ data.tar.gz: aad329e8d107294400e2ea177cd6d7ef4e40751b6bf57fa4987782705d4c9f30ba0f013df1e24e73f96af27ec98a90189f4207f1fbc6eec79726012bc7a19bad
data/.rubocop.yml CHANGED
@@ -4,3 +4,13 @@ Documentation:
4
4
  Metrics/BlockLength:
5
5
  Exclude:
6
6
  - "spec/**/*"
7
+ - "*.gemspec"
8
+
9
+ Style/FrozenStringLiteralComment:
10
+ Enabled: false
11
+
12
+ Style/SafeNavigation:
13
+ Enabled: false
14
+
15
+ Lint/SendWithMixinArgument:
16
+ Enabled: false
data/.travis.yml CHANGED
@@ -1,20 +1,27 @@
1
1
  language: ruby
2
2
 
3
3
  rvm:
4
- - 2.1.9
5
- - 2.2.5
6
- - 2.3.1
4
+ - 2.4.9
5
+ - 2.5.7
6
+ - 2.6.5
7
+ - 2.7.0
7
8
  - ruby-head
9
+ - jruby-head
8
10
 
9
11
  matrix:
10
12
  allow_failures:
11
13
  - rvm: ruby-head
14
+ - rvm: jruby-head
12
15
 
13
16
  gemfile:
14
17
  - Gemfile
15
18
 
16
19
  sudo: false
17
20
 
21
+ before_install:
22
+ - gem update --system
23
+ - gem update bundler
24
+
18
25
  script:
19
26
  - bundle exec rspec
20
27
  - bundle exec rubocop
data/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # carrierwave-base64 changelog
2
2
 
3
+ ## 2.9.0
4
+
5
+ - Mimemagic gem is replaced with Marcel (#87, @oakbow)
6
+
7
+ ## 2.8.0
8
+
9
+ - Mime Type is now detected from file contents, falling back to the type, specified by the user. (#73, @justisb)
10
+
11
+ ## 2.7.0
12
+
13
+ - Railtie is not required by default, so the gem can be used in non Rails app (@sleepingstu)
14
+
15
+ ## 2.6.1
16
+
17
+ This release fixes the issue that the public API of the gem was changed in 2.6.0, by switching from RFC 2045 to RFC 4648 standard for base64 strings.
18
+
19
+ - Switched back to RFC 2045 standard for base64 strings (@lebedev-yury)
20
+
3
21
  ## 2.6.0
4
22
 
5
23
  - Fixed the issue with base64 string not being validated (#64, @sjdrabbani)
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # Carrierwave::Base64
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/carrierwave-base64.svg)](http://badge.fury.io/rb/carrierwave-base64)
4
- [![Build Status](https://travis-ci.org/lebedev-yury/carrierwave-base64.svg?branch=master)](https://travis-ci.org/lebedev-yury/carrierwave-base64)
5
- [![Code Climate](https://codeclimate.com/github/lebedev-yury/carrierwave-base64/badges/gpa.svg)](https://codeclimate.com/github/lebedev-yury/carrierwave-base64)
4
+ [![Build Status](https://travis-ci.org/y9v/carrierwave-base64.svg?branch=master)](https://travis-ci.org/y9v/carrierwave-base64)
5
+ [![Code Climate](https://codeclimate.com/github/y9v/carrierwave-base64/badges/gpa.svg)](https://codeclimate.com/github/y9v/carrierwave-base64)
6
6
 
7
7
  Upload files encoded as base64 to carrierwave.
8
8
 
@@ -32,7 +32,7 @@ Mount the uploader to your model:
32
32
  mount_base64_uploader :image, ImageUploader
33
33
  ```
34
34
 
35
- 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
36
36
 
37
37
  ## Upload file extension
38
38
 
@@ -68,9 +68,7 @@ mount_base64_uploader :image, ImageUploader, file_name: -> { 'userpic' }
68
68
 
69
69
  ## Data format
70
70
 
71
- The string with the encoded data, should be prefixed with Data URI scheme format.
72
-
73
- 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.
74
72
 
75
73
  ```
76
74
  data:image/jpeg;base64,(base64 encoded data)
data/Rakefile CHANGED
@@ -1,8 +1 @@
1
1
  require 'bundler/gem_tasks'
2
-
3
- require 'rspec/core/rake_task'
4
-
5
- desc 'Run all examples'
6
- RSpec::Core::RakeTask.new(:spec)
7
-
8
- task default: [:spec]
@@ -1,4 +1,4 @@
1
- lib = File.expand_path('../lib', __FILE__)
1
+ lib = File.expand_path('lib', __dir__)
2
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
 
4
4
  require 'carrierwave/base64/version'
@@ -19,17 +19,19 @@ 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', '>= 0.8.0'
22
+ spec.add_dependency 'carrierwave', '>= 2.2.1'
23
23
  spec.add_dependency 'mime-types', '~> 3.0'
24
+ spec.add_dependency 'marcel', '~> 1.0.0'
24
25
 
25
- spec.add_development_dependency 'rails', '~> 4'
26
- spec.add_development_dependency 'sqlite3'
27
- spec.add_development_dependency 'mongoid'
26
+ spec.add_development_dependency 'bundler', '~> 2.1'
28
27
  spec.add_development_dependency 'carrierwave-mongoid'
29
- spec.add_development_dependency 'bundler', '~> 1.7'
30
- spec.add_development_dependency 'rake', '~> 10.0'
31
- spec.add_development_dependency 'rspec', '~> 2.14'
32
- spec.add_development_dependency 'sham_rack'
28
+ spec.add_development_dependency 'mongoid'
33
29
  spec.add_development_dependency 'pry'
30
+ spec.add_development_dependency 'rails', '~> 5'
31
+ spec.add_development_dependency 'rake', '~> 12.3.3'
32
+ spec.add_development_dependency 'rspec', '~> 2.14'
34
33
  spec.add_development_dependency 'rubocop'
34
+ spec.add_development_dependency 'sham_rack'
35
+ spec.add_development_dependency 'sqlite3'
36
+ spec.add_development_dependency 'yard'
35
37
  end
@@ -2,19 +2,11 @@ require 'mime/types/full'
2
2
  require 'carrierwave/base64/version'
3
3
  require 'carrierwave/base64/exceptions'
4
4
  require 'carrierwave/base64/base64_string_io'
5
+ require 'carrierwave/base64/mounting_helper'
5
6
  require 'carrierwave/base64/adapter'
7
+ require 'carrierwave/base64/railtie' if defined?(Rails)
6
8
 
7
9
  module Carrierwave
8
10
  module Base64
9
- class Railtie < Rails::Railtie
10
- ActiveSupport.on_load :active_record do
11
- ActiveRecord::Base.extend Carrierwave::Base64::Adapter
12
- end
13
-
14
- ActiveSupport.on_load :mongoid do
15
- Mongoid::Document::ClassMethods.send :include,
16
- Carrierwave::Base64::Adapter
17
- end
18
- end
19
11
  end
20
12
  end
@@ -1,42 +1,32 @@
1
1
  module Carrierwave
2
2
  module Base64
3
+ # Module with .mount_base64_uploader method, that is mixed in to
4
+ # ActiveRecord::Base or Mongoid::Document::ClassMethods
3
5
  module Adapter
4
- # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
5
- # rubocop:disable Metrics/CyclomaticComplexity
6
- # rubocop:disable Metrics/PerceivedComplexity
6
+ # Mounts the carrierwave uploader that can accept a base64 encoded
7
+ # string as input. It also accepts regular file uploads.
8
+ #
9
+ # @param attribute [Symbol] the attribute to mount this uploader on
10
+ # @param uploader_class [Carrierwave::Uploader] the uploader class to
11
+ # mount
12
+ # @param options [Hash{Symbol => Object}] a set of options
13
+ # @option options [Proc] :file_name Proc that must return a file name
14
+ # without extension
15
+ #
16
+ # @example Mount the uploader and specify the file name
17
+ # mount_base64_uploader :image, ImageUploader,
18
+ # file_name: -> (u) { u.username }
19
+ #
20
+ # @return [Symbol] the defined writer method name
7
21
  def mount_base64_uploader(attribute, uploader_class, options = {})
8
22
  mount_uploader attribute, uploader_class, options
9
23
  options[:file_name] ||= proc { attribute }
10
24
 
11
- if options[:file_name].is_a?(String)
12
- warn(
13
- '[Deprecation warning] Setting `file_name` option to a string is '\
14
- 'deprecated and will be removed in 3.0.0. If you want to keep the '\
15
- 'existing behaviour, wrap the string in a Proc'
16
- )
17
- end
25
+ Carrierwave::Base64::MountingHelper.check_for_deprecations(options)
18
26
 
19
- define_method "#{attribute}=" do |data|
20
- return if data == send(attribute).to_s
21
-
22
- if respond_to?("#{attribute}_will_change!") && data.present?
23
- send "#{attribute}_will_change!"
24
- end
25
-
26
- return super(data) unless data.is_a?(String) &&
27
- data.strip.start_with?('data')
28
-
29
- filename = if options[:file_name].respond_to?(:call)
30
- options[:file_name].call(self)
31
- else
32
- options[:file_name]
33
- end.to_s
34
-
35
- super Carrierwave::Base64::Base64StringIO.new(data.strip, filename)
36
- end
37
- # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
38
- # rubocop:enable Metrics/CyclomaticComplexity
39
- # rubocop:enable Metrics/PerceivedComplexity
27
+ Carrierwave::Base64::MountingHelper.define_writer(
28
+ self, attribute, options
29
+ )
40
30
  end
41
31
  end
42
32
  end
@@ -1,27 +1,56 @@
1
+ require 'marcel'
2
+
1
3
  module Carrierwave
2
4
  module Base64
5
+ # Class that decodes a base64 string, builds a StringIO for the
6
+ # decoded bytes, and extracts the file MIME type to build a file
7
+ # name with extension.
3
8
  class Base64StringIO < StringIO
4
- attr_accessor :file_extension, :file_name
9
+ # @return [String] the file name without extension
10
+ attr_reader :file_name
11
+
12
+ # @return [String] the file extension for the uploaded file
13
+ attr_reader :file_extension
5
14
 
15
+ # Returns a StringIO with decoded bytes from the base64 encoded
16
+ # string and builds a file name with extension for the uploaded file,
17
+ # based on the MIME type specified in the base64 encoded string.
18
+ #
19
+ # @param encoded_file [String] the base64 encoded file contents
20
+ # @param file_name [String] the file name without extention
21
+ #
22
+ # @raise [ArgumentError] If the base64 encoded string is empty
23
+ #
24
+ # @return [StringIO] StringIO with decoded bytes
6
25
  def initialize(encoded_file, file_name)
7
26
  description, encoded_bytes = encoded_file.split(',')
8
27
 
28
+ raise ArgumentError unless encoded_bytes
29
+ raise ArgumentError if encoded_bytes.eql?('(null)')
30
+
9
31
  @file_name = file_name
10
- @file_extension = get_file_extension description
11
- bytes = ::Base64.strict_decode64 encoded_bytes
32
+ bytes = ::Base64.decode64 encoded_bytes
33
+ @file_extension = get_file_extension description, bytes
12
34
 
13
35
  super bytes
14
36
  end
15
37
 
38
+ # Returns a file name with extension, based on the MIME type specified
39
+ # in the base64 encoded string.
40
+ #
41
+ # @return [String] File name with extention
16
42
  def original_filename
17
43
  File.basename("#{@file_name}.#{@file_extension}")
18
44
  end
19
45
 
20
46
  private
21
47
 
22
- def get_file_extension(description)
23
- content_type = description.split(';base64').first
24
- mime_type = MIME::Types[content_type].first
48
+ # Determine content type from input, with provided type as fallback
49
+ def get_file_extension(description, bytes)
50
+ detected_type = Marcel::Magic.by_magic(bytes)
51
+ content_type = (detected_type && detected_type.type) ||
52
+ description.split(';base64').first
53
+ mime_type = MIME::Types[content_type].last
25
54
  unless mime_type
26
55
  raise Carrierwave::Base64::UnknownMimeTypeError,
27
56
  "Unknown MIME type: #{content_type}"
@@ -1,5 +1,7 @@
1
1
  module Carrierwave
2
2
  module Base64
3
+ # Exception that gets raised when base64 encoded string
4
+ # is of unknown MIME type
3
5
  class UnknownMimeTypeError < ::ArgumentError; end
4
6
  end
5
7
  end
@@ -0,0 +1,63 @@
1
+ module Carrierwave
2
+ module Base64
3
+ # Module with helper functions for mounting uploaders
4
+ module MountingHelper
5
+ module_function
6
+
7
+ # Checks for deprecations and prints a warning if found any.
8
+ # @private
9
+ #
10
+ # @param options [Hash{Symbol => Object}] the uploader options
11
+ # @return [void]
12
+ def check_for_deprecations(options)
13
+ return unless options[:file_name].is_a?(String)
14
+
15
+ warn(
16
+ '[Deprecation warning] Setting `file_name` option to a string is '\
17
+ 'deprecated and will be removed in 3.0.0. If you want to keep the '\
18
+ 'existing behaviour, wrap the string in a Proc'
19
+ )
20
+ end
21
+
22
+ # Returns a file name for the uploaded file.
23
+ # @private
24
+ #
25
+ # @param model_instance [Object] the model instance object
26
+ # @param options [Hash{Symbol => Object}] the uploader options
27
+ # @return [String] File name without extension
28
+ def file_name(model_instance, options)
29
+ if options[:file_name].respond_to?(:call)
30
+ options[:file_name].call(model_instance)
31
+ else
32
+ options[:file_name]
33
+ end.to_s
34
+ end
35
+
36
+ # Defines an attribute writer method on the class with mounted uploader.
37
+ # @private
38
+ #
39
+ # @param klass [Class] the class with mounted uploader
40
+ # @param attr [Symbol] the attribute for which the writer will be defined
41
+ # @param options [Hash{Symbol => Object}] a set of options
42
+ # @return [Symbol] the defined writer method name
43
+ def define_writer(klass, attr, options)
44
+ klass.send(:define_method, "#{attr}=") do |data|
45
+ # rubocop:disable Lint/NonLocalExitFromIterator
46
+ return if data.to_s.empty? || data == send(attr).to_s
47
+
48
+ # rubocop:enable Lint/NonLocalExitFromIterator
49
+
50
+ send("#{attr}_will_change!") if respond_to?("#{attr}_will_change!")
51
+
52
+ return super(data) unless data.is_a?(String) &&
53
+ data.strip.start_with?('data')
54
+
55
+ super Carrierwave::Base64::Base64StringIO.new(
56
+ data.strip,
57
+ Carrierwave::Base64::MountingHelper.file_name(self, options)
58
+ )
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,15 @@
1
+ module Carrierwave
2
+ module Base64
3
+ # Railtie class to load the carrierwave-base64 adapters
4
+ # Loads adapters for ActiveRecord and Mongoid
5
+ class Railtie < Rails::Railtie
6
+ ActiveSupport.on_load :active_record do
7
+ ActiveRecord::Base.extend Carrierwave::Base64::Adapter
8
+ end
9
+
10
+ ActiveSupport.on_load :mongoid do
11
+ Mongoid::Document::ClassMethods.include Carrierwave::Base64::Adapter
12
+ end
13
+ end
14
+ end
15
+ end
@@ -1,5 +1,5 @@
1
1
  module Carrierwave
2
2
  module Base64
3
- VERSION = '2.6.0'.freeze
3
+ VERSION = '2.9.0'.freeze
4
4
  end
5
5
  end
data/spec/adapter_spec.rb CHANGED
@@ -30,11 +30,10 @@ RSpec.describe Carrierwave::Base64::Adapter do
30
30
 
31
31
  it 'creates a file' do
32
32
  subject.save!
33
- subject.reload
34
33
 
35
34
  expect(
36
35
  subject.image.current_path
37
- ).to eq file_path('../uploads', 'image.jpeg')
36
+ ).to eq file_path('../uploads', 'image.png')
38
37
  end
39
38
  end
40
39
  end
@@ -86,7 +85,6 @@ RSpec.describe Carrierwave::Base64::Adapter do
86
85
 
87
86
  it 'saves the file' do
88
87
  subject.save!
89
- subject.reload
90
88
 
91
89
  expect(
92
90
  subject.image.current_path
@@ -103,11 +101,10 @@ RSpec.describe Carrierwave::Base64::Adapter do
103
101
 
104
102
  it 'creates a file' do
105
103
  subject.save!
106
- subject.reload
107
104
 
108
105
  expect(
109
106
  subject.image.current_path
110
- ).to eq file_path('../uploads', 'batman.jpeg')
107
+ ).to eq file_path('../uploads', 'batman.png')
111
108
  end
112
109
 
113
110
  it 'sets will_change for the attribute' do
@@ -126,10 +123,9 @@ RSpec.describe Carrierwave::Base64::Adapter do
126
123
  it 'should invoke the file_name proc upon each upload' do
127
124
  subject.save!
128
125
  another_subject.save!
129
- another_subject.reload
130
126
  expect(
131
127
  another_subject.image.current_path
132
- ).to eq file_path('../uploads', 'robin.jpeg')
128
+ ).to eq file_path('../uploads', 'robin.png')
133
129
  end
134
130
  end
135
131
  end
@@ -140,21 +136,39 @@ RSpec.describe Carrierwave::Base64::Adapter do
140
136
  file_path('fixtures', 'base64_image.fixture')
141
137
  ).strip
142
138
  subject.save!
143
- subject.reload
144
139
  end
145
140
 
146
141
  it 'keeps the file when setting the attribute to existing value' do
147
- expect(File.exist?(subject.reload.image.file.file)).to be_truthy
142
+ expect(File.exist?(subject.image.file.file)).to be_truthy
148
143
  subject.update!(image: subject.image.to_s)
149
- expect(File.exist?(subject.reload.image.file.file)).to be_truthy
144
+ expect(File.exist?(subject.image.file.file)).to be_truthy
150
145
  end
151
146
 
152
147
  it 'removes files when remove_* is set to true' do
153
148
  subject.remove_image = true
154
149
  subject.save!
155
- expect(subject.reload.image.file).to be_nil
150
+ expect(subject.image.file).to be_nil
156
151
  end
157
152
  end
158
153
  end
154
+
155
+ context 'models with presence validation on attribute with uploader' do
156
+ subject do
157
+ User.validates(:image, presence: true)
158
+ User.mount_base64_uploader(:image, uploader)
159
+ User.new
160
+ end
161
+
162
+ before(:each) do
163
+ subject.image = File.read(
164
+ file_path('fixtures', 'base64_image.fixture')
165
+ ).strip
166
+ subject.save!
167
+ end
168
+
169
+ it 'gives no false positive on presence validation' do
170
+ expect { subject.update!(username: 'new-username') }.not_to raise_error
171
+ end
172
+ end
159
173
  end
160
174
  end
@@ -2,17 +2,19 @@ RSpec.describe Carrierwave::Base64::Base64StringIO do
2
2
  %w[application/vnd.openxmlformats-officedocument.wordprocessingml.document
3
3
  image/jpeg application/pdf audio/mpeg].each do |content_type|
4
4
  context "correct #{content_type} data" do
5
- let(:data) do
6
- "data:#{content_type};base64,VGhpcyBpcyB0ZXN0IHN0cmluZw=="
7
- end
8
-
9
5
  let(:file_extension) do
10
6
  MIME::Types[content_type].last.preferred_extension
11
7
  end
12
8
 
9
+ let(:data) do
10
+ file_name = "test.#{file_extension}"
11
+ bytes = File.read(file_path('fixtures', file_name))
12
+ "data:#{content_type};base64,#{::Base64.encode64(bytes)}"
13
+ end
14
+
13
15
  subject { described_class.new data, 'file' }
14
16
 
15
- it 'determines the file format from the Data URI content type' do
17
+ it 'determines the file format from the content type' do
16
18
  expect(subject.file_extension).to eql(file_extension)
17
19
  end
18
20
 
@@ -36,22 +38,16 @@ RSpec.describe Carrierwave::Base64::Base64StringIO do
36
38
  end
37
39
 
38
40
  context 'invalid image data' do
39
- it 'raises UnknownMimeTypeError for unknown mime types' do
41
+ it 'raises ArgumentError for invalid image data' do
40
42
  expect do
41
43
  described_class.new('/9j/4AAQSkZJRgABAQEASABIAADKdhH//2Q==', 'file')
42
- end.to raise_error(Carrierwave::Base64::UnknownMimeTypeError)
44
+ end.to raise_error(ArgumentError)
43
45
  end
44
46
 
45
47
  it 'raises ArgumentError if base64 data equals to (null)' do
46
48
  expect do
47
49
  described_class.new('data:image/jpeg;base64,(null)', 'file')
48
- end.to raise_error(ArgumentError, 'invalid base64')
49
- end
50
-
51
- it 'raises ArgumentError if base64 data contains white space' do
52
- expect do
53
- described_class.new 'data:image/jpeg;base64,VGhpcyBpc yB0Z==', 'file'
54
- end.to raise_error(ArgumentError, 'invalid base64')
50
+ end.to raise_error(ArgumentError)
55
51
  end
56
52
  end
57
53
  end
@@ -1 +1 @@
1
- data:image/jpeg;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==
1
+ data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==
Binary file
Binary file
Binary file
Binary file
File without changes
data/spec/spec_helper.rb CHANGED
@@ -14,7 +14,6 @@ require 'carrierwave/mongoid'
14
14
 
15
15
  require 'carrierwave/base64'
16
16
 
17
- ActiveRecord::Base.raise_in_transactional_callbacks = true
18
17
  ActiveRecord::Base.establish_connection(
19
18
  adapter: 'sqlite3',
20
19
  database: ':memory:'
@@ -29,3 +28,15 @@ def file_path(*paths)
29
28
  end
30
29
 
31
30
  CarrierWave.root = ''
31
+
32
+ # Add preferred file types similar to how users would implement custom types
33
+ content_types = {
34
+ 'audio/mpeg' => 'mp3'
35
+ }
36
+ content_types.each do |content_type, extension|
37
+ MIME::Types.add(
38
+ MIME::Type.new(content_type).tap do |type|
39
+ type.preferred_extension = extension
40
+ end
41
+ )
42
+ 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.6.0
4
+ version: 2.9.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: 2017-10-12 00:00:00.000000000 Z
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: 0.8.0
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: 0.8.0
26
+ version: 2.2.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: mime-types
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -39,21 +39,35 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '3.0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: rails
42
+ name: marcel
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 1.0.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 1.0.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
59
  - - "~>"
46
60
  - !ruby/object:Gem::Version
47
- version: '4'
61
+ version: '2.1'
48
62
  type: :development
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
66
  - - "~>"
53
67
  - !ruby/object:Gem::Version
54
- version: '4'
68
+ version: '2.1'
55
69
  - !ruby/object:Gem::Dependency
56
- name: sqlite3
70
+ name: carrierwave-mongoid
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
73
  - - ">="
@@ -81,7 +95,7 @@ dependencies:
81
95
  - !ruby/object:Gem::Version
82
96
  version: '0'
83
97
  - !ruby/object:Gem::Dependency
84
- name: carrierwave-mongoid
98
+ name: pry
85
99
  requirement: !ruby/object:Gem::Requirement
86
100
  requirements:
87
101
  - - ">="
@@ -95,33 +109,33 @@ dependencies:
95
109
  - !ruby/object:Gem::Version
96
110
  version: '0'
97
111
  - !ruby/object:Gem::Dependency
98
- name: bundler
112
+ name: rails
99
113
  requirement: !ruby/object:Gem::Requirement
100
114
  requirements:
101
115
  - - "~>"
102
116
  - !ruby/object:Gem::Version
103
- version: '1.7'
117
+ version: '5'
104
118
  type: :development
105
119
  prerelease: false
106
120
  version_requirements: !ruby/object:Gem::Requirement
107
121
  requirements:
108
122
  - - "~>"
109
123
  - !ruby/object:Gem::Version
110
- version: '1.7'
124
+ version: '5'
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: rake
113
127
  requirement: !ruby/object:Gem::Requirement
114
128
  requirements:
115
129
  - - "~>"
116
130
  - !ruby/object:Gem::Version
117
- version: '10.0'
131
+ version: 12.3.3
118
132
  type: :development
119
133
  prerelease: false
120
134
  version_requirements: !ruby/object:Gem::Requirement
121
135
  requirements:
122
136
  - - "~>"
123
137
  - !ruby/object:Gem::Version
124
- version: '10.0'
138
+ version: 12.3.3
125
139
  - !ruby/object:Gem::Dependency
126
140
  name: rspec
127
141
  requirement: !ruby/object:Gem::Requirement
@@ -136,6 +150,20 @@ dependencies:
136
150
  - - "~>"
137
151
  - !ruby/object:Gem::Version
138
152
  version: '2.14'
153
+ - !ruby/object:Gem::Dependency
154
+ name: rubocop
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
139
167
  - !ruby/object:Gem::Dependency
140
168
  name: sham_rack
141
169
  requirement: !ruby/object:Gem::Requirement
@@ -151,7 +179,7 @@ dependencies:
151
179
  - !ruby/object:Gem::Version
152
180
  version: '0'
153
181
  - !ruby/object:Gem::Dependency
154
- name: pry
182
+ name: sqlite3
155
183
  requirement: !ruby/object:Gem::Requirement
156
184
  requirements:
157
185
  - - ">="
@@ -165,7 +193,7 @@ dependencies:
165
193
  - !ruby/object:Gem::Version
166
194
  version: '0'
167
195
  - !ruby/object:Gem::Dependency
168
- name: rubocop
196
+ name: yard
169
197
  requirement: !ruby/object:Gem::Requirement
170
198
  requirements:
171
199
  - - ">="
@@ -200,11 +228,17 @@ files:
200
228
  - lib/carrierwave/base64/adapter.rb
201
229
  - lib/carrierwave/base64/base64_string_io.rb
202
230
  - lib/carrierwave/base64/exceptions.rb
231
+ - lib/carrierwave/base64/mounting_helper.rb
232
+ - lib/carrierwave/base64/railtie.rb
203
233
  - lib/carrierwave/base64/version.rb
204
234
  - spec/adapter_spec.rb
205
235
  - spec/base64_string_io_spec.rb
206
236
  - spec/fixtures/base64_image.fixture
207
- - spec/fixtures/test.jpg
237
+ - spec/fixtures/test.docx
238
+ - spec/fixtures/test.jpeg
239
+ - spec/fixtures/test.mp3
240
+ - spec/fixtures/test.pdf
241
+ - spec/fixtures/test.png
208
242
  - spec/spec_helper.rb
209
243
  - spec/support/custom_expectations/warn_expectation.rb
210
244
  - spec/support/models.rb
@@ -213,7 +247,7 @@ homepage: https://github.com/lebedev-yury/carrierwave-base64
213
247
  licenses:
214
248
  - MIT
215
249
  metadata: {}
216
- post_install_message:
250
+ post_install_message:
217
251
  rdoc_options: []
218
252
  require_paths:
219
253
  - lib
@@ -228,16 +262,19 @@ required_rubygems_version: !ruby/object:Gem::Requirement
228
262
  - !ruby/object:Gem::Version
229
263
  version: '0'
230
264
  requirements: []
231
- rubyforge_project:
232
- rubygems_version: 2.6.11
233
- signing_key:
265
+ rubygems_version: 3.1.4
266
+ signing_key:
234
267
  specification_version: 4
235
268
  summary: Upload images encoded as base64 to carrierwave.
236
269
  test_files:
237
270
  - spec/adapter_spec.rb
238
271
  - spec/base64_string_io_spec.rb
239
272
  - spec/fixtures/base64_image.fixture
240
- - spec/fixtures/test.jpg
273
+ - spec/fixtures/test.docx
274
+ - spec/fixtures/test.jpeg
275
+ - spec/fixtures/test.mp3
276
+ - spec/fixtures/test.pdf
277
+ - spec/fixtures/test.png
241
278
  - spec/spec_helper.rb
242
279
  - spec/support/custom_expectations/warn_expectation.rb
243
280
  - spec/support/models.rb