Files
discordeno/util/urlToBase64.ts
Danny May 0910965de5 Fix sending files through a rest proxy (#2593)
* Fix rest proxy not working with files

* Fix some credits

* Add tests

* Fix test

* Remove some usage of any

* Fix mime matching

* Fix formatting issues
2022-11-20 16:50:50 -06:00

10 lines
387 B
TypeScript

import { encode } from "./base64.ts";
/** Converts a url to base 64. Useful for example, uploading/creating server emojis. */
export async function urlToBase64(url: string) {
const buffer = await fetch(url).then((res) => res.arrayBuffer());
const imageStr = encode(buffer);
const type = url.substring(url.lastIndexOf(".") + 1);
return `data:image/${type};base64,${imageStr}`;
}