Iframe not load file pdf > 2MB
Chuyển đổi base64 to BlobUrl là xong
export function base64ToBlobUrl({
base64String,
contentType,
}: {
base64String: string;
contentType: string;
}) {
if (includes(base64String, "base64")) {
const parts = base64String?.split(";base64,");
const type = parts[0]?.split(":")[1];
const b64Data = parts[1];
// Convert the base64 string to a Uint8Array
const byteCharacters = atob(b64Data);
const byteNumbers = new Array(byteCharacters.length);
for (let i = 0; i < byteCharacters.length; i++) {
byteNumbers[i] = byteCharacters.charCodeAt(i);
}
const byteArray = new Uint8Array(byteNumbers);
// Create a Blob object from the binary data
const blob = new Blob([byteArray], { type: contentType || type });
// Create a URL for the Blob object
const blobUrl = URL.createObjectURL(blob);
return blobUrl;
}
}
All rights reserved