Skip to main content
Module

x/fetchbase64/src/remote.ts

A simple module to fetch Base64 data of any image/gif, remote or local.
Latest
File
import { encode } from '../deps.ts'
export const fetchRemote = async (url: string, onlyData?: boolean) => { const resp = await fetch(url) if(resp.status !== 200) throw new Error(`Request Failed. Server responsed with code ${resp.status}`) const contentType = resp.headers.get('content-type') ?? 'application/octet-stream'; const buff = await resp.arrayBuffer() const data = encode(buff) return onlyData ? data : `data:${contentType};base64,${data}`}