Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow setting of default mime type for files with no extension #63

Merged
merged 1 commit into from
Jul 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,12 @@ Sets the `Expires` header on the uploaded files.

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

### defaultMimeType

Sets the default mime type, used when it cannot be determined from the file extension.

*Default:* `application/octet-stream`

## Prerequisites

The following properties are expected to be present on the deployment `context` object:
Expand Down
2 changes: 2 additions & 0 deletions lib/s3.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ module.exports = CoreObject.extend({
var cacheControl = options.cacheControl;
var expires = options.expires;

mime.default_type = options.defaultMimeType || mime.lookup('bin');

return filePaths.map(function(filePath) {
var basePath = path.join(cwd, filePath);
var data = fs.readFileSync(basePath);
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/dist/index
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>Some HTML</p>
41 changes: 41 additions & 0 deletions tests/unit/lib/s3-nodetest.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,47 @@ describe('s3', function() {
assert.equal(s3Params.Expires, '2010');
});
});

it('sets the content type using defaultMimeType', function() {
var s3Params;
s3Client.putObject = function(params, cb) {
s3Params = params;
cb();
};

var options = {
filePaths: ['index'],
cwd: process.cwd() + '/tests/fixtures/dist',
defaultMimeType: 'text/html'
};

var promises = subject.upload(options);

return assert.isFulfilled(promises)
.then(function() {
assert.equal(s3Params.ContentType, 'text/html; charset=utf-8');
});
});

it('sets the content type to the default', function() {
var s3Params;
s3Client.putObject = function(params, cb) {
s3Params = params;
cb();
};

var options = {
filePaths: ['index'],
cwd: process.cwd() + '/tests/fixtures/dist'
};

var promises = subject.upload(options);

return assert.isFulfilled(promises)
.then(function() {
assert.equal(s3Params.ContentType, 'application/octet-stream');
});
});
});

describe('with a manifestPath specified', function () {
Expand Down