1.0.0 • Published 3 years ago

blob-url-file v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

js-file

transformation functions of file/blob/base64

usage

npm install blob-url-to-file

import { blobToBase64 } from 'blob-url-to-file'

blobToBase64

const b64Data = await blobToBase64(blob);

urlToBlob

const blob = await urlToBlob(url); // url is a dataUrl, like: 'data:application/json;base64,ewogICJoZWxsbyI6ICJ3b3JsZCIKfQ==';

base64ToBlob

const blob = await base64ToBlob({ b64Data="", contentType="", sliceSize=512, name=""}); // b64Data is required;

fileUrlToUrl(fileUrl)

const fileUrl =
  "https://upload.wikimedia.org/wikipedia/commons/thumb/2/21/Falco_peregrinus_-_01.jpg/1920px-Falco_peregrinus_-_01.jpg";
const url = await fileUrlToUrl(fileUrl);

downloadFile(fileUrl, name)

// autodownload
const fileUrl =
  "https://upload.wikimedia.org/wikipedia/commons/thumb/2/21/Falco_peregrinus_-_01.jpg/1920px-Falco_peregrinus_-_01.jpg";
downloadFile(fileUrl, name);