Skip to content

base64ToFile

Convert Base64 string to File.

Usage

js
import { base64ToFile } from 'js-cool'

Signature

typescript
function base64ToFile(
  base64: string,
  filename: string,
  mime?: string
): File

Parameters

ParameterTypeDescription
base64stringBase64 encoded string
filenamestringOutput filename
mimestringMIME type (optional)

Returns

File - File object.

Examples

js
const file = base64ToFile(
  'SGVsbG8gV29ybGQ=',
  'hello.txt',
  'text/plain'
)

// From data URL
const imageFile = base64ToFile(
  'data:image/png;base64,iVBOR...',
  'image.png'
)

Released under the MIT License.