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?)