aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/PhotoStorage.pm
diff options
context:
space:
mode:
authorDave Arter <davea@mysociety.org>2019-04-05 18:49:32 +0100
committerDave Arter <davea@mysociety.org>2019-06-06 11:59:21 +0100
commitff3b747698f577876bff25512ac137c6677ccab7 (patch)
tree8d11c4376cbb2d7a60b79c94fc9827ef3c417d81 /perllib/FixMyStreet/PhotoStorage.pm
parent1a1be49646218b2217e25e82e6666749f78dc612 (diff)
[Hounslow] Add general enquiries functionality
This functionality allows a cobrand to replace the /contact form with a form that creates hidden reports which are sent via Open311. The form also allows file uploads in addition to photos. This functionality is currently enabled for the Hounslow cobrand and others cobrands can enable it by defining setup_general_enquiries_stash which primarily sets up the appropriate categories and default values for the report.
Diffstat (limited to 'perllib/FixMyStreet/PhotoStorage.pm')
-rw-r--r--perllib/FixMyStreet/PhotoStorage.pm28
1 files changed, 28 insertions, 0 deletions
diff --git a/perllib/FixMyStreet/PhotoStorage.pm b/perllib/FixMyStreet/PhotoStorage.pm
index a441fb718..558c93749 100644
--- a/perllib/FixMyStreet/PhotoStorage.pm
+++ b/perllib/FixMyStreet/PhotoStorage.pm
@@ -37,5 +37,33 @@ sub get_fileid {
}
+=head2 base64_decode_upload
+
+base64 decode the temporary on-disk uploaded file if
+it's encoded that way. Modifies the file in-place.
+Catalyst::Request::Upload doesn't do this automatically
+unfortunately.
+
+=cut
+
+sub base64_decode_upload {
+ my ( $c, $upload ) = @_;
+
+ my $transfer_encoding = $upload->headers->header('Content-Transfer-Encoding');
+ if (defined $transfer_encoding && $transfer_encoding eq 'base64') {
+ my $decoded = decode_base64($upload->slurp);
+ if (open my $fh, '>', $upload->tempname) {
+ binmode $fh;
+ print $fh $decoded;
+ close $fh
+ } else {
+ $c->log->info('Couldn\'t open temp file to save base64 decoded image: ' . $!);
+ $c->stash->{photo_error} = _("Sorry, we couldn't save your file(s), please try again.");
+ return ();
+ }
+ }
+
+}
+
1;