-
-
Notifications
You must be signed in to change notification settings - Fork 568
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: pdf preview base64 too large to preview (#1031)
- Loading branch information
Showing
3 changed files
with
11 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,6 @@ | ||
export const urlToBase64 = async ( | ||
url: string | ||
): Promise<{ base64: string; base64WithPrefix: string }> => { | ||
try { | ||
const response = await fetch(url); | ||
const blob = await response.blob(); | ||
import { getBlobFromUrl } from '../office/utils'; | ||
|
||
return new Promise((resolve, reject) => { | ||
const reader = new FileReader(); | ||
reader.onloadend = () => { | ||
const base64String = String(reader.result); | ||
base64String && | ||
resolve({ | ||
base64: base64String.split(',')[1], | ||
base64WithPrefix: base64String, | ||
}); | ||
}; | ||
reader.onerror = reject; | ||
reader.readAsDataURL(blob); | ||
}); | ||
} catch (error) { | ||
throw new Error(`Failed to convert URL to base64: ${(error as Error)?.message}`); | ||
} | ||
export const getBlobUrlFromUrl = async (url: string) => { | ||
const blob = await getBlobFromUrl(url); | ||
return URL.createObjectURL(blob); | ||
}; |