active_storage_base64 0.1.2 → 0.1.3

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
2
  SHA256:
3
- metadata.gz: 3f06ab3b77fc8bc3dd993d1313ad0136d2ab2bdf6a776a0dc7414c5af9fd75c3
4
- data.tar.gz: 5f00568a8b09f02018bb6049203d4a02ffaca06ba7769ac04b8c001e0061fa2b
3
+ metadata.gz: 3a8fb507b829cbc1391e67980bb733767fb33273921af4bace259c2a7af9fcab
4
+ data.tar.gz: '059a2c3c923ecbad36c6f26f1a97f4bca2d0b66fe373702e7858a3b24c9cd4e5'
5
5
  SHA512:
6
- metadata.gz: 74e9c1008d1f9dad166133f44014ae715d779eca9d03d1177d4923de2d54db4389840756fac7aadcd09f87beb0eae8b0603f39f520660dc380313557f245107f
7
- data.tar.gz: cdc6293595a7187c91b2543bc67893ba05b605506072686002e123f02ad47d671876399d16acfa26fe1bcea7dfd17c8723db895dac9f23198de5f8d20ea1dead
6
+ metadata.gz: 6e6756f8888101cbc476e09fd42eacf331b784249d51f4a8abd313b516848135bdb5f27b35a51ac5b1c7726150ca71e2f2f57c11e23c3580d2afce62b3cb32f4
7
+ data.tar.gz: af8702891ae2527294e8f9e2de7623f938b892a6347bb7b916094df54e338f8892468ba061506b5a92c1423075a025301906a7e087005be01d62cf89aa5f2f18
data/README.md CHANGED
@@ -10,7 +10,7 @@ Gem used to add support for base64 images for Rails's ActiveStorage.
10
10
 
11
11
  In order to get the gem working on your project you just need to add the gem to your project like this:
12
12
  ```ruby
13
- gem 'active-storage-base64'
13
+ gem 'active_storage_base64'
14
14
  ```
15
15
 
16
16
  ### Prerequisites
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'active_storage_base64'
3
- s.version = '0.1.2'
3
+ s.version = '0.1.3'
4
4
  s.summary = 'Base64 support for ActiveStorage'
5
5
  s.description = s.summary
6
6
 
@@ -10,11 +10,19 @@ module ActiveStorageSupport
10
10
  end
11
11
 
12
12
  def fill_attachment_data(attachment, base64_data)
13
- return unless base64_data.try(:is_a?, String) && base64_data =~ /^data:(.*?);(.*?),(.*)$/
13
+ return unless base64_data.try(:is_a?, String) && base64_data.strip.start_with?('data')
14
14
 
15
- attachment[:io] = StringIO.new(Base64.decode64(Regexp.last_match(3)))
16
- attachment[:content_type] ||= Regexp.last_match(1)
15
+ headers, data = base64_data.split(',')
16
+ decoded_data = Base64.decode64(data)
17
+
18
+ attachment[:io] = StringIO.new(decoded_data)
19
+ attachment[:content_type] ||= content_type(headers)
17
20
  attachment[:filename] ||= Time.current.to_i.to_s
18
21
  end
22
+
23
+ def content_type(headers)
24
+ headers =~ /^data:(.*?)$/
25
+ Regexp.last_match(1).split(';base64').first
26
+ end
19
27
  end
20
28
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_storage_base64
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ricardo Cortio
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-01-17 00:00:00.000000000 Z
11
+ date: 2019-01-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails