Skip to content

Commit 47e4db7

Browse files
committed
Allow setting of default mime type for files with no extension
1 parent a239020 commit 47e4db7

File tree

4 files changed

+50
-0
lines changed

4 files changed

+50
-0
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,12 @@ Sets the `Expires` header on the uploaded files.
169169

170170
*Default:* `Mon Dec 31 2029 21:00:00 GMT-0300 (CLST)`
171171

172+
### defaultMimeType
173+
174+
Sets the default mime type, used when it cannot be determined from the file extension.
175+
176+
*Default:* `application/octet-stream`
177+
172178
## Prerequisites
173179

174180
The following properties are expected to be present on the deployment `context` object:

lib/s3.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ module.exports = CoreObject.extend({
9292
var cacheControl = options.cacheControl;
9393
var expires = options.expires;
9494

95+
mime.default_type = options.defaultMimeType || mime.lookup('bin');
96+
9597
return filePaths.map(function(filePath) {
9698
var basePath = path.join(cwd, filePath);
9799
var data = fs.readFileSync(basePath);

tests/fixtures/dist/index

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<p>Some HTML</p>

tests/unit/lib/s3-nodetest.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,47 @@ describe('s3', function() {
146146
assert.equal(s3Params.Expires, '2010');
147147
});
148148
});
149+
150+
it('sets the content type using defaultMimeType', function() {
151+
var s3Params;
152+
s3Client.putObject = function(params, cb) {
153+
s3Params = params;
154+
cb();
155+
};
156+
157+
var options = {
158+
filePaths: ['index'],
159+
cwd: process.cwd() + '/tests/fixtures/dist',
160+
defaultMimeType: 'text/html'
161+
};
162+
163+
var promises = subject.upload(options);
164+
165+
return assert.isFulfilled(promises)
166+
.then(function() {
167+
assert.equal(s3Params.ContentType, 'text/html; charset=utf-8');
168+
});
169+
});
170+
171+
it('sets the content type to the default', function() {
172+
var s3Params;
173+
s3Client.putObject = function(params, cb) {
174+
s3Params = params;
175+
cb();
176+
};
177+
178+
var options = {
179+
filePaths: ['index'],
180+
cwd: process.cwd() + '/tests/fixtures/dist'
181+
};
182+
183+
var promises = subject.upload(options);
184+
185+
return assert.isFulfilled(promises)
186+
.then(function() {
187+
assert.equal(s3Params.ContentType, 'application/octet-stream');
188+
});
189+
});
149190
});
150191

151192
describe('with a manifestPath specified', function () {

0 commit comments

Comments
 (0)