js create object url base64 pdf binary

Solutions on MaxInterview for js create object url base64 pdf binary by the best coders in the world

showing results for - "js create object url base64 pdf binary"
Aidan
23 Jan 2020
1const b64toBlob = (b64Data, contentType='', sliceSize=512) => {
2  const byteCharacters = atob(b64Data);
3  const byteArrays = [];
4
5  for (let offset = 0; offset < byteCharacters.length; offset += sliceSize) {
6    const slice = byteCharacters.slice(offset, offset + sliceSize);
7
8    const byteNumbers = new Array(slice.length);
9    for (let i = 0; i < slice.length; i++) {
10      byteNumbers[i] = slice.charCodeAt(i);
11    }
12
13    const byteArray = new Uint8Array(byteNumbers);
14    byteArrays.push(byteArray);
15  }
16
17  const blob = new Blob(byteArrays, {type: contentType});
18  return blob;
19}
20
21const blob = b64toBlob(b64Data, contentType);
22const blobUrl = URL.createObjectURL(blob);
23
24window.location = blobUrl;
25