Skip to content

Commit 3ece174

Browse files
authored
fix(File): ensure mime_type (#426)
1 parent a80bacb commit 3ece174

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/file.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ module.exports = function(AV) {
118118
owner: (owner ? owner.id : 'unknown')
119119
};
120120

121-
this.mimeType = mimeType;
121+
this.set('mime_type', mimeType);
122122

123123
if (_.isArray(data)) {
124124
this.attributes.metaData.size = data.length;
@@ -246,6 +246,7 @@ module.exports = function(AV) {
246246
return this.id;
247247
case 'url':
248248
case 'name':
249+
case 'mime_type':
249250
case 'metaData':
250251
case 'createdAt':
251252
case 'updatedAt':
@@ -267,6 +268,7 @@ module.exports = function(AV) {
267268
switch (attrName) {
268269
case 'name':
269270
case 'url':
271+
case 'mime_type':
270272
case 'base64':
271273
case 'metaData':
272274
this.attributes[attrName] = value;
@@ -396,7 +398,12 @@ module.exports = function(AV) {
396398
this.attributes.metaData.mime_type = type;
397399
}
398400
this._qiniu_key = key;
399-
return AVRequest(route, null, null, 'POST', data);
401+
return AVRequest(route, null, null, 'POST', data).then(response => {
402+
if (response.mime_type) {
403+
this.set('mime_type', response.mime_type);
404+
}
405+
return response;
406+
});
400407
},
401408

402409
/**
@@ -475,14 +482,16 @@ module.exports = function(AV) {
475482
var value = AV.Object.prototype.parse(response);
476483
value.attributes = {
477484
name: value.name,
478-
url: value.url
485+
url: value.url,
486+
mime_type: value.mime_type,
479487
};
480488
value.attributes.metaData = value.metaData || {};
481489
// clean
482490
delete value.objectId;
483491
delete value.metaData;
484492
delete value.url;
485493
delete value.name;
494+
delete value.mime_type;
486495
_.extend(this, value);
487496
return this;
488497
});

test/file.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ describe('File', function() {
1818
expect(file.ownerId()).to.be.ok();
1919
expect(file.id).to.be.ok();
2020
expect(file.metaData('format')).to.be('txt file');
21+
expect(file.get('mime_type')).to.be('text/plain');
2122
return file.destroy({ useMasterKey: true });
2223
});
2324
});
@@ -41,6 +42,7 @@ describe('File', function() {
4142
} else {
4243
done(err);
4344
}
45+
file.destroy({ useMasterKey: true });
4446
});
4547
});
4648
});
@@ -140,6 +142,7 @@ describe('File', function() {
140142
expect(file).to.be.a(AV.File);
141143
expect(file.id).to.be(fileId);
142144
expect(file.name()).to.be('myfile.txt');
145+
expect(file.get('mime_type')).to.be('text/plain');
143146
expect(typeof file.url()).to.be('string');
144147
});
145148
});

0 commit comments

Comments
 (0)