-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetBase64ImgFromUrl.js
68 lines (58 loc) · 2.49 KB
/
getBase64ImgFromUrl.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
'use strict'
var _interopRequireDefault = require('@babel/runtime/helpers/interopRequireDefault')
Object.defineProperty(exports, '__esModule', {
value: true,
})
exports.getBase64ImgFromUrl = void 0
var _regenerator = _interopRequireDefault(require('@babel/runtime/regenerator'))
var _asyncToGenerator2 = _interopRequireDefault(
require('@babel/runtime/helpers/asyncToGenerator'),
)
var _axios = _interopRequireDefault(require('axios'))
var getBase64ImgFromUrl =
/*#__PURE__*/
(function() {
var _ref = (0, _asyncToGenerator2.default)(
/*#__PURE__*/
_regenerator.default.mark(function _callee(url) {
var response, bufferString, base64Img
return _regenerator.default.wrap(
function _callee$(_context) {
while (1) {
switch ((_context.prev = _context.next)) {
case 0:
_context.next = 2
return (0, _axios.default)({
method: 'GET',
responseType: 'arraybuffer',
url: ''.concat(url),
})
case 2:
response = _context.sent
// tslint:disable-next-line
bufferString = new Buffer(
response.data,
).toString('base64')
base64Img = 'data:'
.concat(
response.headers['content-type'],
';base64,',
)
.concat(bufferString)
return _context.abrupt('return', base64Img)
case 6:
case 'end':
return _context.stop()
}
}
},
_callee,
this,
)
}),
)
return function getBase64ImgFromUrl(_x) {
return _ref.apply(this, arguments)
}
})()
exports.getBase64ImgFromUrl = getBase64ImgFromUrl