Skip to content

Commit 6dde942

Browse files
committed
Fixes peclik#89 S3 plugin compatibility
1 parent 3c03ef3 commit 6dde942

File tree

1 file changed

+5
-16
lines changed

1 file changed

+5
-16
lines changed

lib/clipboard_image_paste/attachment_patch.rb

+5-16
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def save_attachments_with_pasted_images(attachments, author=User.current)
3535
if attachments && attachments.is_a?(Hash)
3636
attachments.each do |key,value|
3737
next unless key.start_with?('1000')
38-
value['file'] = PastedImage.new(value.delete('data'), value.delete('name'))
38+
value['file'] = PastedImage.new(value.delete('data'), value.delete('name')).raw
3939
end
4040
end
4141
save_attachments_without_pasted_images(attachments, author)
@@ -44,18 +44,15 @@ def save_attachments_with_pasted_images(attachments, author=User.current)
4444
end
4545

4646
# Mimics uploaded file field data.
47-
class PastedImage
47+
class PastedImage < StringIO
48+
4849
def initialize(data, name)
49-
@raw = StringIO.new(remove_alpha(Base64.decode64(data.to_s)))
50+
super(remove_alpha(Base64.decode64(data.to_s)))
5051
@name = name.to_s.strip
5152
@name = 'picture.png' if @name.blank?
5253
@name += '.png' unless @name.end_with?('.png')
5354
end
5455

55-
def size
56-
@raw.size
57-
end
58-
5956
def original_filename
6057
@name
6158
end
@@ -64,14 +61,7 @@ def content_type
6461
"image/png"
6562
end
6663

67-
def read(*args)
68-
@raw.read(*args)
69-
end
70-
71-
def eof?
72-
@raw.eof?
73-
end
74-
64+
protected
7565
# remove alpha channel (because PDF export doesn't support PNGs with alpha channel,
7666
# see https://github.com/peclik/clipboard_image_paste/issues/24)
7767
def remove_alpha(imgData)
@@ -95,7 +85,6 @@ def remove_alpha(imgData)
9585
return imgData
9686
end if not ($clipboard_image_paste_remove_alpha && Object.const_defined?(:Magick))
9787
end
98-
9988
end
10089

10190
# Send patches - guarded against including the module multiple time

0 commit comments

Comments
 (0)