|
3824 | 3824 | return chunks.join(""); |
3825 | 3825 | }; |
3826 | 3826 |
|
| 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 = []; |
3827 | 3834 |
|
| 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 | + }; |
3828 | 3867 | // A list of file extensions to mime types as found here: |
3829 | 3868 | // http://stackoverflow.com/questions/58510/using-net-how-can-you-find-the- |
3830 | 3869 | // mime-type-of-a-file-based-on-the-file-signature |
|
4108 | 4147 | this._metaData.size = data.length; |
4109 | 4148 | } else if (data && data.base64) { |
4110 | 4149 | this._source = AV.Promise.as(data.base64, guessedType); |
4111 | | - this._metaData.size = data.base64.length; |
| 4150 | + this._metaData.size = decodeBase64(data.base64).length; |
4112 | 4151 | } else if (typeof(File) !== "undefined" && data instanceof File) { |
4113 | 4152 | this._source = readAsync(data, type); |
4114 | 4153 | } else if(AV._isNode && Buffer.isBuffer(data)) { |
|
4271 | 4310 | self._qiniu_key = key; |
4272 | 4311 | self._base64 = base64; |
4273 | 4312 | if(!self._metaData.size){ |
4274 | | - self._metaData.size = base64.length; |
| 4313 | + self._metaData.size = decodeBase64(base64).length; |
4275 | 4314 | } |
4276 | 4315 | return AV._request("qiniu", null, null, 'POST', data); |
4277 | 4316 | }).then(function(response) { |
|
4308 | 4347 | metaData: self._metaData, |
4309 | 4348 | }; |
4310 | 4349 | if(!self._metaData.size){ |
4311 | | - self._metaData.size = base64.length; |
| 4350 | + self._metaData.size = decodeBase64(base64).length; |
4312 | 4351 | } |
4313 | 4352 | return AV._request("files", self._name, null, 'POST', data); |
4314 | 4353 | }).then(function(response) { |
4315 | 4354 | self._name = response.name; |
4316 | 4355 | self._url = response.url; |
4317 | 4356 | self.id = response.objectId; |
4318 | | - self._metaData.size = response.size; |
| 4357 | + if(response.size) |
| 4358 | + self._metaData.size = response.size; |
4319 | 4359 | return self; |
4320 | 4360 | }); |
4321 | 4361 | } |
|
4330 | 4370 | self._name = response.name; |
4331 | 4371 | self._url = response.url; |
4332 | 4372 | self.id = response.objectId; |
4333 | | - self._metaData.size = response.size; |
| 4373 | + if(response.size) |
| 4374 | + self._metaData.size = response.size; |
4334 | 4375 | return self; |
4335 | 4376 | }); |
4336 | 4377 | } |
|
0 commit comments