active_storage_base64 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/active_storage_base64.gemspec +1 -1
- data/lib/active_storage_support/base64_attach.rb +11 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3a8fb507b829cbc1391e67980bb733767fb33273921af4bace259c2a7af9fcab
|
4
|
+
data.tar.gz: '059a2c3c923ecbad36c6f26f1a97f4bca2d0b66fe373702e7858a3b24c9cd4e5'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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 '
|
13
|
+
gem 'active_storage_base64'
|
14
14
|
```
|
15
15
|
|
16
16
|
### Prerequisites
|
@@ -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
|
13
|
+
return unless base64_data.try(:is_a?, String) && base64_data.strip.start_with?('data')
|
14
14
|
|
15
|
-
|
16
|
-
|
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.
|
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-
|
11
|
+
date: 2019-01-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|