files-base64

1.0.2 • Public • Published

files-base64

Some functions to handle files and base64 strings

Getting Started

npm i files-base64@latest

Usage

here is example for fileToBase64 function.

The function takes a file as an argument and returns a Promise that resolves with the base64 representation of the file. If there is an error, the Promise will be rejected with the error.

import { fileToBase64 } from "files-base64"

const inputFile = document.querySelector('input[type="file"]').files[0];  // file
fileToBase64(inputFile)
  .then(result => {
    console.log(result);
  })
  .catch(error => {
    console.error(error);
  });

here is example for fileToBase64 function.

The function takes two arguments: url which is the base64 representation of the file, and fileName which is an optional argument that sets the name of the file. It returns a File object that can be used for further processing.

import { fileToBase64 } from "files-base64"

const base64Url = "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAkGBxMSEhUSEhIVFhUVFRcVFRU...";
const file = await base64ToFile(base64Url, "image.jpeg");
console.log(file);

Dependencies

The functions use the FileReader API, the fetch API, and the File constructor, which are available in modern browsers. There are no other dependencies.

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.2
    1
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.0.2
    1
  • 1.0.1
    0
  • 1.0.0
    0

Package Sidebar

Install

npm i files-base64

Weekly Downloads

1

Version

1.0.2

License

ISC

Unpacked Size

2.43 kB

Total Files

3

Last publish

Collaborators

  • paneruvipin