From 5a43b27f7940be9697f312c550fa2de11a9e14d7 Mon Sep 17 00:00:00 2001 From: Kohei Yoshino Date: Fri, 10 Aug 2018 08:56:19 -0400 Subject: Bug 602313 - Allow creation of attachments by pasting an image from clipboard, as well as by drag-and-dropping a file from desktop --- attachment.cgi | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'attachment.cgi') diff --git a/attachment.cgi b/attachment.cgi index d1b260407..875de6a50 100755 --- a/attachment.cgi +++ b/attachment.cgi @@ -33,6 +33,7 @@ use URI; use URI::QueryParam; use URI::Escape qw(uri_escape_utf8); use File::Basename qw(basename); +use MIME::Base64 qw(decode_base64); # For most scripts we don't make $cgi and $template global variables. But # when preparing Bugzilla for mod_perl, this script used these @@ -552,20 +553,30 @@ sub insert { # Get the filehandle of the attachment. my $data_fh = $cgi->upload('data'); my $attach_text = $cgi->param('attach_text'); + my $data_base64 = $cgi->param('data_base64'); + my $data; + my $filename; if ($attach_text) { # Convert to unix line-endings if pasting a patch if (scalar($cgi->param('ispatch'))) { $attach_text =~ s/[\012\015]{1,2}/\012/g; } + $data = $attach_text; + $filename = "file_$bugid.txt"; + } elsif ($data_base64) { + $data = decode_base64($data_base64); + $filename = $cgi->param('filename') || "file_$bugid"; + } else { + $data = $filename = $data_fh; } my $attachment = Bugzilla::Attachment->create( {bug => $bug, creation_ts => $timestamp, - data => $attach_text || $data_fh, + data => $data, description => scalar $cgi->param('description'), - filename => $attach_text ? "file_$bugid.txt" : $data_fh, + filename => $filename, ispatch => scalar $cgi->param('ispatch'), isprivate => scalar $cgi->param('isprivate'), mimetype => $content_type, -- cgit v1.2.3-24-g4f1b