[Rt-commit] rt branch, 4.4.1/amazon-s3-content-type, created. rt-4.4.1-2-gd50773d

Jim Brandt jbrandt at bestpractical.com
Thu Nov 10 12:04:07 EST 2016


The branch, 4.4.1/amazon-s3-content-type has been created
        at  d50773df0ed0e4686970545b3634177d138a4abc (commit)

- Log -----------------------------------------------------------------
commit af3848fec0e1e14bb70620558432f33ab54e7e36
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..a7c5347 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, $a) = @_;
 
     # 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 => $a->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..d6d2de9 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, $a) = @_;
 
     # 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..f2a9a98 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, $a) = @_;
 
     my $dropbox = $self->Dropbox;
 
diff --git a/sbin/rt-externalize-attachments.in b/sbin/rt-externalize-attachments.in
index 9782347..5990656 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 $a = shift;
 
     my $key = Digest::SHA::sha256_hex( $content );
-    my ($ok, $msg) = $ExternalStorage->Store( $key => $content );
+    my ($ok, $msg) = $ExternalStorage->Store( $key => $content, $a );
     return ($ok, $msg) unless defined $ok;
 
     return ($key);

commit d50773df0ed0e4686970545b3634177d138a4abc
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 a7c5347..6de03a5 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();

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


More information about the rt-commit mailing list