|
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 = []; |
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 | | - }; |
3867 | 3827 | // A list of file extensions to mime types as found here: |
3868 | 3828 | // http://stackoverflow.com/questions/58510/using-net-how-can-you-find-the- |
3869 | 3829 | // mime-type-of-a-file-based-on-the-file-signature |
|
4147 | 4107 | this._metaData.size = data.length; |
4148 | 4108 | } else if (data && data.base64) { |
4149 | 4109 | this._source = AV.Promise.as(data.base64, guessedType); |
4150 | | - this._metaData.size = decodeBase64(data.base64).length; |
4151 | 4110 | } else if (typeof(File) !== "undefined" && data instanceof File) { |
4152 | 4111 | this._source = readAsync(data, type); |
4153 | 4112 | } else if(AV._isNode && Buffer.isBuffer(data)) { |
|
4309 | 4268 | self._metaData.mime_type = type; |
4310 | 4269 | self._qiniu_key = key; |
4311 | 4270 | self._base64 = base64; |
4312 | | - if(!self._metaData.size){ |
4313 | | - self._metaData.size = decodeBase64(base64).length; |
4314 | | - } |
4315 | 4271 | return AV._request("qiniu", null, null, 'POST', data); |
4316 | 4272 | }).then(function(response) { |
4317 | 4273 | self._url = response.url; |
|
4346 | 4302 | mime_type: type, |
4347 | 4303 | metaData: self._metaData, |
4348 | 4304 | }; |
4349 | | - if(!self._metaData.size){ |
4350 | | - self._metaData.size = decodeBase64(base64).length; |
4351 | | - } |
4352 | 4305 | return AV._request("files", self._name, null, 'POST', data); |
4353 | 4306 | }).then(function(response) { |
4354 | 4307 | self._name = response.name; |
|
0 commit comments