Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
### 2.6.1 (Next)

* [#45](https://github.com/mongoid/mongoid-grid_fs/pull/45): Encode stored file bytes rather than the model description in Base64 and data URIs - [@yudho](https://github.com/yudho), [@dblock](https://github.com/dblock).
* [#86](https://github.com/mongoid/mongoid-grid_fs/pull/86): Expand persisted GridFS coverage for streaming, upload failures, namespaces, attributes, queries, historical records without `updateDate`, and Rails responses - [@dblock](https://github.com/dblock).
* [#85](https://github.com/mongoid/mongoid-grid_fs/pull/85): Report test coverage to Coveralls and update CI badges - [@dblock](https://github.com/dblock).
* [#84](https://github.com/mongoid/mongoid-grid_fs/pull/84): Migrate Danger to danger-pr-comment workflows - [@dblock](https://github.com/dblock).
Expand Down
2 changes: 1 addition & 1 deletion lib/mongoid/grid_fs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ def data
end

def base64
Array(to_s).pack('m')
Array(data).pack('m')
end

def data_uri(_options = {})
Expand Down
10 changes: 10 additions & 0 deletions test/grid_fs_interfaces_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,16 @@ def test_normalized_upload_attributes_survive_reload
assert_equal "binary\x00payload".b, file.data
end

def test_base64_and_data_uri_encode_the_stored_bytes
payload = "binary\x00\xffpayload".b * 12
file = @namespace.put(StringIO.new(payload), filename: 'encoded.bin', chunk_size: 8)
file = @namespace.get(file.id)

assert_equal [payload].pack('m'), file.base64
assert_equal payload, file.base64.unpack1('m')
assert_equal "data:application/octet-stream;base64,#{[payload].pack('m').chomp}", file.data_uri
end

def test_explicit_gridfs_attributes
uploaded_at = Time.utc(2021, 2, 3)
file = @namespace.put(
Expand Down
2 changes: 1 addition & 1 deletion test/mongoid-grid_fs_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
g = assert { GridFs.get(id) }

content_type = g.content_type
base64 = [g.to_s].pack('m').chomp
base64 = [g.data].pack('m').chomp

data_uri = "data:#{content_type};base64,".concat(base64)

Expand Down
Loading