[rt-users] Large attachments - how to warn user before dropped
Schultz, Eric
ESchultz at corp.untd.com
Thu Jan 25 12:52:29 EST 2007
> I would like to warn the user before dropping a large attachment and
> give them the opportunity to make a different selection.
> I saw this in an earlier email (dated 2006-02-24 from Eric Shultz
> "TruncateLongAttachments .."), where he had modified the RT
> code to do
> just that. I've been attempting to do the same thing in Update.html,
> but failing. I can't seem to determine the filesize with the
> information at hand. Can anyone point me in the right
> direction? Or is
> Update.html not the place to be making these changes?
Hi Karen. Unfortunately, I've made a bunch of other changes to the
3.4.x code, so I can't easily provide you with just a simple patch.
What I can provide is the code I added for this functionality, however,
and at about what point in the file share/html/Ticket/Update.html.
Note, however, that I did not set TruncateLongAttachments in
RT_SiteConfig.pm, I set DropLongAttachments to 1. Here are my changes:
#1:
-----------
<& /Ticket/Elements/Tabs,
Ticket => $TicketObj,
Title=> $title &>
+ <& /Elements/ListActions, actions => \@Actions &>
+
<FORM ACTION="Update.html" NAME="TicketUpdate"
METHOD=POST enctype="multipart/form-data">
<input type="hidden" name="QuoteTransaction" value="<%
$ARGS{QuoteTransaction} %>">
-----------
#2:
-----------
<%INIT>
my $CanRespond = 0;
my $CanComment = 0;
my $title;
+ my @Actions;
my $TicketObj = LoadTicket($id);
-----------
#3:
-----------
$session{'Attachments'} = { %{$session{'Attachments'} || {}},
$ARGS{'Attach'} => $attachment };
+
+ my $latest_attach = $ARGS{'Attach'};
+
+ # Check the length of all attachments put together, compensating
+ # for encoding overhead (* .75) like is done elsewhere in the
code.
+ my $total_length = 0;
+ foreach my $key (keys %{$session{'Attachments'}}) {
+ my $length = length(
${$session{'Attachments'}}{$key}->stringify_body );
+ $total_length += int($length * .75 / 1024);
+ }
+
+ # If the total of all attachments exceeds the RT config parameter,
+ # and we're told to drop long attachments, drop all of them.
+ # But still allow a message update.
+ my $maxsize = int($RT::MaxAttachmentSize * .75 / 1024);
+ if ($total_length > $maxsize and $RT::DropLongAttachments) {
+ $RT::Logger->warning( "Exceeded maximum attachment size. Total
length: ${total_length}k (max: ${maxsize}k)" );
+ push( @Actions, "Attachment '$latest_attach' not uploaded: total
size of all attachments (${total_length}k) would exceed limit
(${maxsize}k)" );
+ delete ${$session{'Attachments'}}{$latest_attach}; # remove
only the latest one that tipped the scales
+ delete $ARGS{SubmitTicket}; # don't go to the Display.html
page
+ }
}
# }}}
# delete temporary storage entry to make WebUI clean
unless (keys %{$session{'Attachments'}} and $ARGS{'UpdateAttach'}) {
delete $session{'Attachments'};
-----------
Let me know how that works for you.
Eric Schultz
United Online, Inc.
More information about the rt-users
mailing list