Skip to content

Commit 31263e6

Browse files
authored
refactor(file): use the key generated by the server (#632)
* refactor(utils): create Buffer with Buffer.from * refactor(file): use the key generated by the server
1 parent ed4af1a commit 31263e6

File tree

3 files changed

+2
-17
lines changed

3 files changed

+2
-17
lines changed

src/file.js

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@ const debug = require('debug')('leancloud:file');
99
const parseBase64 = require('./utils/parse-base64');
1010

1111
module.exports = function(AV) {
12-
const hexOctet = () =>
13-
Math.floor((1 + Math.random()) * 0x10000)
14-
.toString(16)
15-
.substring(1);
16-
1712
// port from browserify path module
1813
// since react-native packager won't shim node modules.
1914
const extname = path => {
@@ -484,23 +479,13 @@ module.exports = function(AV) {
484479
name += this._extName;
485480
extName = this._extName;
486481
}
487-
// Create 16-bits uuid as qiniu key.
488-
const key =
489-
hexOctet() +
490-
hexOctet() +
491-
hexOctet() +
492-
hexOctet() +
493-
hexOctet() +
494-
extName;
495482
const data = {
496-
key,
497483
name,
498484
keep_file_name: authOptions.keepFileName,
499485
ACL: this._acl,
500486
mime_type: type,
501487
metaData: this.attributes.metaData,
502488
};
503-
this._qiniu_key = key;
504489
return AVRequest('fileTokens', null, null, 'POST', data, authOptions);
505490
},
506491

src/uploader/qiniu.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ module.exports = function(uploadInfo, data, file, saveOptions = {}) {
1717
headers: file._uploadHeaders,
1818
data: {
1919
name: file.attributes.name,
20-
key: uploadInfo.key || file._qiniu_key,
20+
key: uploadInfo.key,
2121
token: uptoken,
2222
},
2323
onprogress: saveOptions.onprogress,

src/utils/parse-base64.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ var dataURLToBlob = function(base64) {
33
if (base64.split(',')[0] && base64.split(',')[0].indexOf('base64') >= 0) {
44
base64 = base64.split(',')[1];
55
}
6-
return new Buffer(base64, 'base64');
6+
return Buffer.from(base64, 'base64');
77
};
88

99
module.exports = dataURLToBlob;

0 commit comments

Comments
 (0)