carrierwave-base64 1.3 → 1.4
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
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b81321c57f7f1474d1fa455b97329989f4484d5d
|
4
|
+
data.tar.gz: 2d0f412d61b8fe5f22801a89263ea618f68794f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3117dcaef41677818a683f1f46fce1607e0dbe8081e37ea630a20b65acbb699663e3e332a0d9370c546c8dffc5cb305900d6fa642e548fa73235dc4ccf0ec855
|
7
|
+
data.tar.gz: 2fd4303a312208ce26434e2abca58be7d0d6085411c21881c4a3b7f11f0fc4e171c61e2fb45baa3ac03875d011e50467cd1d8e584dd1592348f478f88b66a2cf
|
@@ -3,27 +3,27 @@ module Carrierwave
|
|
3
3
|
class Base64StringIO < StringIO
|
4
4
|
class ArgumentError < StandardError; end
|
5
5
|
|
6
|
-
attr_accessor :
|
6
|
+
attr_accessor :file_format
|
7
7
|
|
8
|
-
def initialize(
|
9
|
-
description, encoded_bytes =
|
8
|
+
def initialize(encoded_file)
|
9
|
+
description, encoded_bytes = encoded_file.split(",")
|
10
10
|
|
11
11
|
raise ArgumentError unless encoded_bytes
|
12
12
|
|
13
|
-
@
|
13
|
+
@file_format = get_file_format description
|
14
14
|
bytes = ::Base64.decode64 encoded_bytes
|
15
15
|
|
16
16
|
super bytes
|
17
17
|
end
|
18
18
|
|
19
19
|
def original_filename
|
20
|
-
File.basename("
|
20
|
+
File.basename("file.#{@file_format}")
|
21
21
|
end
|
22
22
|
|
23
23
|
private
|
24
24
|
|
25
|
-
def
|
26
|
-
regex =
|
25
|
+
def get_file_format(description)
|
26
|
+
regex = /([a-z]+);base64\z/
|
27
27
|
regex.match(description).try(:[], 1)
|
28
28
|
end
|
29
29
|
end
|
@@ -7,7 +7,7 @@ module Carrierwave
|
|
7
7
|
mount_uploader attribute, uploader_class
|
8
8
|
|
9
9
|
define_method "#{attribute}=" do |data|
|
10
|
-
if data.present? && data.is_a?(String) && data.strip.start_with?("data
|
10
|
+
if data.present? && data.is_a?(String) && data.strip.start_with?("data")
|
11
11
|
super(Carrierwave::Base64::Base64StringIO.new(data.strip))
|
12
12
|
else
|
13
13
|
super(data)
|
@@ -6,11 +6,24 @@ RSpec.describe Carrierwave::Base64::Base64StringIO do
|
|
6
6
|
subject { described_class.new image_data }
|
7
7
|
|
8
8
|
it "determines the image format from the Dara URI scheme" do
|
9
|
-
expect(subject.
|
9
|
+
expect(subject.file_format).to eql("jpg")
|
10
10
|
end
|
11
11
|
|
12
12
|
it "should respond to :original_filename" do
|
13
|
-
expect(subject.original_filename).to eql("
|
13
|
+
expect(subject.original_filename).to eql("file.jpg")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context "correct pdf data" do
|
18
|
+
let(:image_data) { "data:application/pdf;base64,/9j/4AAQSkZJRgABAQEASABKdhH//2Q==" }
|
19
|
+
subject { described_class.new image_data }
|
20
|
+
|
21
|
+
it "determines the image format from the Dara URI scheme" do
|
22
|
+
expect(subject.file_format).to eql("pdf")
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should respond to :original_filename" do
|
26
|
+
expect(subject.original_filename).to eql("file.pdf")
|
14
27
|
end
|
15
28
|
end
|
16
29
|
|
@@ -28,7 +28,7 @@ RSpec.describe Carrierwave::Base64::ActiveRecord do
|
|
28
28
|
subject.image = File.read(file_path("fixtures", "base64_image.fixture")).strip
|
29
29
|
subject.save!
|
30
30
|
subject.reload
|
31
|
-
expect(subject.image.current_path).to eq file_path("../uploads", "
|
31
|
+
expect(subject.image.current_path).to eq file_path("../uploads", "file.jpg")
|
32
32
|
end
|
33
33
|
end
|
34
34
|
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: '1.
|
4
|
+
version: '1.4'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yury Lebedev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-04-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: carrierwave
|