Giter VIP home page Giter VIP logo

files-base64's Introduction

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.