[Rt-commit] rt branch, 4.4-trunk, updated. rt-4.4.1-140-g193312d

Shawn Moore shawn at bestpractical.com
Thu Dec 1 15:14:02 EST 2016


The branch, 4.4-trunk has been updated
       via  193312de2822d942f5ffa39dd5d30ab32a26e453 (commit)
       via  b3793935243914ffd8ed11143e0504f355a03ba8 (commit)
       via  f9eb378c579e141c05e9846f21f2ddbeeb1359b0 (commit)
      from  d83ce00ed5b8d697a8e6d681ce4d8de0d67a0949 (commit)

Summary of changes:
 lib/RT/ExternalStorage/AmazonS3.pm | 33 +++++++++++++++++++++++++++++++--
 lib/RT/ExternalStorage/Disk.pm     |  2 +-
 lib/RT/ExternalStorage/Dropbox.pm  |  2 +-
 sbin/rt-externalize-attachments.in |  5 +++--
 4 files changed, 36 insertions(+), 6 deletions(-)

- Log -----------------------------------------------------------------
commit f9eb378c579e141c05e9846f21f2ddbeeb1359b0
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Thu Nov 10 11:50:31 2016 -0500

    Pass attachment object to Store for additional attachment metadata
    
    When storing attachments in Amazon S3 specifically, if content type
    isn't passed, Amazon will guess wrong and send a content type of
    binary/octet-stream when you access the attachment via the Amazon
    link. Pass the attachment object to Store to get the content type
    RT has stored. This makes the attachment object available to Store
    for future metadata needs.

diff --git a/lib/RT/ExternalStorage/AmazonS3.pm b/lib/RT/ExternalStorage/AmazonS3.pm
index 1ded7a1..a8b22c3 100644
--- a/lib/RT/ExternalStorage/AmazonS3.pm
+++ b/lib/RT/ExternalStorage/AmazonS3.pm
@@ -141,13 +141,16 @@ sub Get {
 
 sub Store {
     my $self = shift;
-    my ($sha, $content) = @_;
+    my ($sha, $content, $attachment) = @_;
 
     # No-op if the path exists already
     return (1) if $self->BucketObj->head_key( $sha );
 
+    # Without content_type, S3 can guess wrong and cause attachments downloaded
+    # via a link to have a content type of binary/octet-stream
     $self->BucketObj->add_key(
-        $sha => $content
+        $sha => $content,
+        { content_type => $attachment->ContentType }
     ) or return (undef, "Failed to write to AmazonS3: " . $self->S3->errstr);
 
     return (1);
diff --git a/lib/RT/ExternalStorage/Disk.pm b/lib/RT/ExternalStorage/Disk.pm
index 60046fe..7ebd2d7 100644
--- a/lib/RT/ExternalStorage/Disk.pm
+++ b/lib/RT/ExternalStorage/Disk.pm
@@ -104,7 +104,7 @@ sub Get {
 
 sub Store {
     my $self = shift;
-    my ($sha, $content) = @_;
+    my ($sha, $content, $attachment) = @_;
 
     # fan out to avoid one gigantic directory which slows down all file access
     $sha =~ m{^(...)(...)(.*)};
diff --git a/lib/RT/ExternalStorage/Dropbox.pm b/lib/RT/ExternalStorage/Dropbox.pm
index 58aeea4..06d4587 100644
--- a/lib/RT/ExternalStorage/Dropbox.pm
+++ b/lib/RT/ExternalStorage/Dropbox.pm
@@ -119,7 +119,7 @@ sub Get {
 
 sub Store {
     my $self = shift;
-    my ($sha, $content) = @_;
+    my ($sha, $content, $attachment) = @_;
 
     my $dropbox = $self->Dropbox;
 
diff --git a/sbin/rt-externalize-attachments.in b/sbin/rt-externalize-attachments.in
index 9782347..5db3816 100644
--- a/sbin/rt-externalize-attachments.in
+++ b/sbin/rt-externalize-attachments.in
@@ -147,7 +147,7 @@ for my $class (qw/RT::Attachments RT::ObjectCustomFieldValues/) {
                 RT->Logger->info("Storing $class $id");
             }
 
-            my ($key, $msg) = Store( $content );
+            my ($key, $msg) = Store( $content, $a );
             unless ($key) {
                 RT->Logger->error("Failed to store $class $id: $msg");
                 exit 1;
@@ -188,9 +188,10 @@ RT->System->SetAttribute( Name => "ExternalStorage", Content => $last );
 
 sub Store {
     my $content = shift;
+    my $attachment = shift;
 
     my $key = Digest::SHA::sha256_hex( $content );
-    my ($ok, $msg) = $ExternalStorage->Store( $key => $content );
+    my ($ok, $msg) = $ExternalStorage->Store( $key => $content, $attachment );
     return ($ok, $msg) unless defined $ok;
 
     return ($key);

commit b3793935243914ffd8ed11143e0504f355a03ba8
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Thu Nov 10 12:03:45 2016 -0500

    Additional docs on connecting to Amazon S3

diff --git a/lib/RT/ExternalStorage/AmazonS3.pm b/lib/RT/ExternalStorage/AmazonS3.pm
index a8b22c3..01b4060 100644
--- a/lib/RT/ExternalStorage/AmazonS3.pm
+++ b/lib/RT/ExternalStorage/AmazonS3.pm
@@ -290,6 +290,32 @@ F<RT_SiteConfig.pm> file:
 
     Set($ExternalStorageDirectLink, 1);
 
+=head1 TROUBLESHOOTING
+
+=head2 Issues Connecting to the Amazon Bucket
+
+Here are some things to check if you receive errors connecting to Amazon S3.
+
+=over
+
+=item *
+
+Double check all of the configuration parameters, including the bucket name. Remember to restart
+the server after changing values for RT to load new settings.
+
+=item *
+
+If you manually created a bucket, make sure it is in your default region. Trying to access
+a bucket in a different region may result in 400 errors.
+
+=item *
+
+Check the permissions on the bucket and make sure they are sufficient for the user RT is
+connecting as to upload and access files. If you are using the direct link option, you will
+need to open permissions further for users to access the attachment via the direct link.
+
+=back
+
 =cut
 
 RT::Base->_ImportOverlays();

commit 193312de2822d942f5ffa39dd5d30ab32a26e453
Merge: d83ce00 b379393
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Thu Dec 1 20:13:58 2016 +0000

    Merge branch '4.4.1/amazon-s3-content-type' into 4.4-trunk


-----------------------------------------------------------------------


More information about the rt-commit mailing list