Skip to content

Commit 13c3a72

Browse files
committed
Fixed issue 6.
1 parent 52a0c8b commit 13c3a72

File tree

1 file changed

+46
-5
lines changed

1 file changed

+46
-5
lines changed

lib/av.js

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3824,7 +3824,46 @@
38243824
return chunks.join("");
38253825
};
38263826

3827+
//https://raw.githubusercontent.com/kvz/phpjs/master/functions/url/base64_decode.js
3828+
var decodeBase64 = function(data) {
3829+
var b64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
3830+
var o1, o2, o3, h1, h2, h3, h4, bits, i = 0,
3831+
ac = 0,
3832+
dec = '',
3833+
tmp_arr = [];
38273834

3835+
if (!data) {
3836+
return data;
3837+
}
3838+
3839+
data += '';
3840+
3841+
do {
3842+
// unpack four hexets into three octets using index points in b64
3843+
h1 = b64.indexOf(data.charAt(i++));
3844+
h2 = b64.indexOf(data.charAt(i++));
3845+
h3 = b64.indexOf(data.charAt(i++));
3846+
h4 = b64.indexOf(data.charAt(i++));
3847+
3848+
bits = h1 << 18 | h2 << 12 | h3 << 6 | h4;
3849+
3850+
o1 = bits >> 16 & 0xff;
3851+
o2 = bits >> 8 & 0xff;
3852+
o3 = bits & 0xff;
3853+
3854+
if (h3 == 64) {
3855+
tmp_arr[ac++] = String.fromCharCode(o1);
3856+
} else if (h4 == 64) {
3857+
tmp_arr[ac++] = String.fromCharCode(o1, o2);
3858+
} else {
3859+
tmp_arr[ac++] = String.fromCharCode(o1, o2, o3);
3860+
}
3861+
} while (i < data.length);
3862+
3863+
dec = tmp_arr.join('');
3864+
3865+
return decodeURIComponent(escape(dec.replace(/\0+$/, '')));
3866+
};
38283867
// A list of file extensions to mime types as found here:
38293868
// http://stackoverflow.com/questions/58510/using-net-how-can-you-find-the-
38303869
// mime-type-of-a-file-based-on-the-file-signature
@@ -4108,7 +4147,7 @@
41084147
this._metaData.size = data.length;
41094148
} else if (data && data.base64) {
41104149
this._source = AV.Promise.as(data.base64, guessedType);
4111-
this._metaData.size = data.base64.length;
4150+
this._metaData.size = decodeBase64(data.base64).length;
41124151
} else if (typeof(File) !== "undefined" && data instanceof File) {
41134152
this._source = readAsync(data, type);
41144153
} else if(AV._isNode && Buffer.isBuffer(data)) {
@@ -4271,7 +4310,7 @@
42714310
self._qiniu_key = key;
42724311
self._base64 = base64;
42734312
if(!self._metaData.size){
4274-
self._metaData.size = base64.length;
4313+
self._metaData.size = decodeBase64(base64).length;
42754314
}
42764315
return AV._request("qiniu", null, null, 'POST', data);
42774316
}).then(function(response) {
@@ -4308,14 +4347,15 @@
43084347
metaData: self._metaData,
43094348
};
43104349
if(!self._metaData.size){
4311-
self._metaData.size = base64.length;
4350+
self._metaData.size = decodeBase64(base64).length;
43124351
}
43134352
return AV._request("files", self._name, null, 'POST', data);
43144353
}).then(function(response) {
43154354
self._name = response.name;
43164355
self._url = response.url;
43174356
self.id = response.objectId;
4318-
self._metaData.size = response.size;
4357+
if(response.size)
4358+
self._metaData.size = response.size;
43194359
return self;
43204360
});
43214361
}
@@ -4330,7 +4370,8 @@
43304370
self._name = response.name;
43314371
self._url = response.url;
43324372
self.id = response.objectId;
4333-
self._metaData.size = response.size;
4373+
if(response.size)
4374+
self._metaData.size = response.size;
43344375
return self;
43354376
});
43364377
}

0 commit comments

Comments
 (0)