S3Sync.net
February 02, 2014, 01:37:42 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Patch for default MIME type  (Read 3296 times)
ddribin
Newbie
*
Posts: 2


View Profile
« on: January 05, 2008, 07:35:22 PM »

Hi all,

Here's a patch against 1.2.3 that adds a --default-mime-type (-t) option.  This MIME type is used if it's not in the MIME types file (S3SYNC_MIME_TYPES_FILE).  Two common values for this would be text/plain and application/octet-stream.

-Dave


diff -r 8b1bb8b568f9 s3sync.rb
--- a/s3sync.rb   Sat Jan 05 17:03:49 2008 -0600
+++ b/s3sync.rb   Sat Jan 05 18:16:22 2008 -0600
@@ -64,7 +64,8 @@ module S3sync
               [ '--expires',        GetoptLong::REQUIRED_ARGUMENT ],
               [ '--cache-control',  GetoptLong::REQUIRED_ARGUMENT ],
          [ '--exclude',        GetoptLong::REQUIRED_ARGUMENT ],
-           [ '--make-dirs',   GetoptLong::NO_ARGUMENT ]
+           [ '--make-dirs',   GetoptLong::NO_ARGUMENT ],
+           [ '--default-mime-type', '-t', GetoptLong::REQUIRED_ARGUMENT]
            )
           
       def S3sync.usage(message = nil)
@@ -76,7 +77,7 @@ module S3sync
   --ssl     -s          --recursive   -r     --delete
   --public-read -p      --expires="<exp>"    --cache-control="<cc>"
   --exclude="<regexp>"  --progress           --debug   -d
-  --make-dirs
+  --make-dirs           --default-mime-type,-t="<mime-type>"
 One of <source> or <destination> must be of S3 format, the other a local path.
 Reminders:
 * An S3 formatted item with bucket 'mybucket' and prefix 'mypre' looks like:
@@ -500,9 +501,20 @@ ENDUSAGE
                headers['Cache-Control'] = $S3syncOptions['--cache-control'] if $S3syncOptions['--cache-control']
                fType = @path.split('.').last
                debug("File extension: #{fType}")
-               if defined?($mimeTypes) and fType != '' and (mType = $mimeTypes[fType]) and mType != ''
-                  debug("Mime type: #{mType}")
-                  headers['Content-Type'] = mType
+               mimeType = nil
+               if !fromNode.directory?
+                  if defined?($mimeTypes) and fType != '' and (mType = $mimeTypes[fType]) and mType != ''
+                     mimeType = mType
+                  end
+                  if mimeType.nil? and !$S3syncOptions['--default-mime-type'].nil?
+                     mimeType = $S3syncOptions['--default-mime-type']
+                  end
+                  if !mimeType.nil?
+                     debug("Mime type: #{mimeType}")
+                     headers['Content-Type'] = mimeType
+                  else
+                     debug("Mime type: <none>")
+                  end
                end
                @result = S3sync.S3try(:put, @bucket, @path, s3o, headers)
                theStream.close if (theStream and not theStream.closed?)

Logged
ferrix
Sr. Member
****
Posts: 363


(I am greg13070 on AWS forum)


View Profile
« Reply #1 on: January 06, 2008, 10:55:34 AM »

Is this a commonly needed feature?  It seems a bit fringe to me, but if you all need it I can include it in the future.
Logged
ddribin
Newbie
*
Posts: 2


View Profile
« Reply #2 on: January 07, 2008, 10:36:22 AM »

It's nice when there's no file extension.  If you're just using S3 for media, that's probably an unlikely scenario, but if you're mirroring your whole website, it may come up once or twice.  I know I've got some text files, like README, that fall under this.

Apache has a similar setting, which is set to text/plain, IIRC.  I think not setting any Content-Type is bad practice.

-Dave

Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!