Skip to content

Commit e926aa0

Browse files
authored
fix(File): calculate file size before fileToken (#488)
1 parent e70dc9e commit e926aa0

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/file.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,22 @@ module.exports = function(AV) {
116116
}
117117
}
118118

119-
if (typeof File !== "undefined" && data instanceof File && data.name) {
120-
this._extName = extname(data.name);
119+
if (typeof File !== "undefined" && data instanceof File) {
120+
if (data.size) {
121+
this.attributes.metaData.size = data.size;
122+
}
123+
if (data.name) {
124+
this._extName = extname(data.name);
125+
}
121126
}
122127

123128
if (!process.env.CLIENT_PLATFORM) {
124129
if (data instanceof require('stream')) {
125130
this._extName = extname(data.path);
126131
}
132+
if (Buffer.isBuffer(data)) {
133+
this.attributes.metaData.size = data.length;
134+
}
127135
}
128136

129137
let owner;
@@ -471,19 +479,15 @@ module.exports = function(AV) {
471479
return data.blob;
472480
}
473481
if (typeof File !== "undefined" && data instanceof File) {
474-
if (data.size) {
475-
this.attributes.metaData.size = data.size;
476-
}
477482
return data;
478483
}
479484
if (!process.env.CLIENT_PLATFORM) {
480485
if (data instanceof require('stream')) {
481486
return data;
482487
}
483-
}
484-
if (typeof Buffer !== "undefined" && Buffer.isBuffer(data)) {
485-
this.attributes.metaData.size = data.length;
486-
return data;
488+
if (Buffer.isBuffer(data)) {
489+
return data;
490+
}
487491
}
488492
throw new TypeError('malformed file data');
489493
}).then(data => {

0 commit comments

Comments
 (0)