Skip to content

Commit ef95b70

Browse files
committed
Merge pull request #46 from elidupuis/detect-mimetype
Add mimetype detection based on `filePattern`/`filePath`
2 parents eb4dc20 + e0f90eb commit ef95b70

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

lib/s3.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ var Promise = require('ember-cli/lib/ext/promise');
44
var fs = require('fs');
55
var path = require('path');
66
var readFile = Promise.denodeify(fs.readFile);
7+
var mime = require('mime-types');
78

89
function headObject(client, params) {
910
return new Promise(function(resolve, reject) {
@@ -47,7 +48,7 @@ module.exports = CoreObject.extend({
4748
Bucket: bucket,
4849
Key: key,
4950
ACL: acl,
50-
ContentType: 'text/html',
51+
ContentType: mime.lookup(options.filePath) || 'text/html',
5152
CacheControl: 'max-age=0, no-cache'
5253
}
5354

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@
5151
"aws-sdk": "^2.1.48",
5252
"core-object": "^1.1.0",
5353
"ember-cli-babel": "^5.1.3",
54-
"ember-cli-deploy-plugin": "^0.2.1"
54+
"ember-cli-deploy-plugin": "^0.2.1",
55+
"mime-types": "^2.1.9"
5556
},
5657
"ember-addon": {
5758
"configPath": "tests/dummy/config"

tests/unit/fixtures/test.tar

198 Bytes
Binary file not shown.

tests/unit/lib/s3-nodetest.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,19 @@ describe('s3', function() {
124124
});
125125
});
126126

127+
it('detects `filePattern` other than `index.html` in order to customize ContentType', function() {
128+
var filePath = 'tests/unit/fixtures/test.tar';
129+
130+
options.filePath = filePath;
131+
var promise = subject.upload(options);
132+
133+
return assert.isFulfilled(promise)
134+
.then(function() {
135+
var expectedContentType = 'application/x-tar';
136+
assert.equal(s3Params.ContentType, expectedContentType, 'contentType is set to `application/x-tar');
137+
});
138+
});
139+
127140
it('allows `prefix` option to be passed to customize upload-path', function() {
128141
var prefix = 'my-app';
129142

0 commit comments

Comments
 (0)