@@ -84,6 +84,35 @@ class S3PutTask extends Service_Amazon_S3
84
84
* @access protected
85
85
*/
86
86
protected $ _acl = 'private ' ;
87
+
88
+ /**
89
+ * File content type
90
+ * Use this to set the content type of your static files
91
+ * Set contentType to "auto" if you want to autodetect the content type based on the source file extension
92
+ *
93
+ * (default value: 'binary/octet-stream')
94
+ *
95
+ * @var string
96
+ * @access protected
97
+ */
98
+ protected $ _contentType = 'binary/octet-stream ' ;
99
+
100
+ /**
101
+ * Extension content type mapper
102
+ *
103
+ * @var array
104
+ * @access protected
105
+ */
106
+ protected $ _extensionContentTypeMapper = array (
107
+ 'js ' => 'application/x-javascript ' ,
108
+ 'css ' => 'text/css ' ,
109
+ 'html ' => 'text/html ' ,
110
+ 'gif ' => 'image/gif ' ,
111
+ 'png ' => 'image/png ' ,
112
+ 'jpg ' => 'image/jpeg ' ,
113
+ 'jpeg ' => 'image/jpeg ' ,
114
+ 'txt ' => 'text/plain '
115
+ );
87
116
88
117
public function setSource ($ source )
89
118
{
@@ -152,6 +181,25 @@ public function getAcl()
152
181
{
153
182
return $ this ->_acl ;
154
183
}
184
+
185
+ public function setContentType ($ contentType )
186
+ {
187
+ $ this ->_contentType = $ contentType ;
188
+ }
189
+
190
+ public function getContentType ()
191
+ {
192
+ if ($ this ->_contentType === 'auto ' ) {
193
+ $ ext = strtolower (substr (strrchr ($ this ->getSource (), '. ' ), 1 ));
194
+ if (isset ($ this ->_extensionContentTypeMapper [$ ext ])) {
195
+ return $ this ->_extensionContentTypeMapper [$ ext ];
196
+ } else {
197
+ return 'binary/octet-stream ' ;
198
+ }
199
+ } else {
200
+ return $ this ->_contentType ;
201
+ }
202
+ }
155
203
156
204
public function setCreateBuckets ($ createBuckets )
157
205
{
@@ -260,6 +308,7 @@ protected function saveObject($object, $data)
260
308
$ object = $ this ->getObjectInstance ($ object );
261
309
$ object ->data = $ data ;
262
310
$ object ->acl = $ this ->getAcl ();
311
+ $ object ->contentType = $ this ->getContentType ();
263
312
$ object ->save ();
264
313
265
314
if (!$ this ->isObjectAvailable ($ object ->key )) {
0 commit comments