Skip to content

Home > robinson > urlToBase64

urlToBase64() function

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

将图片URL转换为Base64编码的字符串

Signature:

typescript
declare function urlToBase64(url: string, suffix?: string): Promise<string>;
declare function urlToBase64(url: string, suffix?: string): Promise<string>;

Parameters

ParameterTypeDescription
urlstring图片URL
suffixstring(Optional) 文件后缀,默认为'image/png'

Returns:

Promise<string>

Promise对象,解析为Base64编码的字符串

Example

urlToBase64('https://example.com/image.png').then(base64 => console.log(base64));

Released under the MIT License.