Skip to content

Commit 3d3debc

Browse files
authored
fix(File): update mime_type in uploader (#430)
1 parent 3396f0c commit 3d3debc

File tree

3 files changed

+5
-7
lines changed

3 files changed

+5
-7
lines changed

src/file.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ module.exports = function(AV) {
1111
// 挂载一些配置
1212
let avConfig = AV._config;
1313

14+
const hexOctet = () => Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1);
15+
1416
// port from browserify path module
1517
// since react-native packager won't shim node modules.
1618
const extname = (path) => {
@@ -388,7 +390,6 @@ module.exports = function(AV) {
388390

389391
// Create 16-bits uuid as qiniu key.
390392
const extName = extname(name) || this._extName;
391-
const hexOctet = () => Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1);
392393
const key = hexOctet() + hexOctet() + hexOctet() + hexOctet() + hexOctet() + extName;
393394
const data = {
394395
key,
@@ -397,9 +398,6 @@ module.exports = function(AV) {
397398
mime_type: type,
398399
metaData: this.attributes.metaData,
399400
};
400-
if (type && !this.attributes.metaData.mime_type) {
401-
this.attributes.metaData.mime_type = type;
402-
}
403401
this._qiniu_key = key;
404402
return AVRequest(route, null, null, 'POST', data).then(response => {
405403
if (response.mime_type) {

src/uploader/qiniu.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ module.exports = function upload(uploadInfo, data, file) {
1010
const uptoken = uploadInfo.token;
1111
return new Promise((resolve, reject) => {
1212
const extra = new qiniu.io.PutExtra();
13-
if (file.attributes.metaData.mime_type) {
14-
extra.mimeType = file.attributes.metaData.mime_type;
13+
if (file.has('mime_type')) {
14+
extra.mimeType = file.get('mime_type');
1515
}
1616
const body = new Buffer(data, 'base64');
1717
qiniu.io.put(uptoken, file._qiniu_key, body, extra, (err) => {

src/uploader/s3.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module.exports = function upload(uploadInfo, data, file, saveOptions = {}) {
88
return new Promise((resolve, reject) => {
99
// 海外节点,针对 S3 才会返回 upload_url
1010
const req = request('PUT', uploadInfo.upload_url)
11-
.set('Content-Type', file.attributes.metaData.mime_type)
11+
.set('Content-Type', file.get('mime_type'))
1212
.send(data);
1313
if (saveOptions.onprogress) {
1414
req.on('progress', saveOptions.onprogress);

0 commit comments

Comments
 (0)