Skip to content

An easy way to interact with files in javascript using NPM.

Notifications You must be signed in to change notification settings

Minterl/fileify

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

fileify-files is a simple and easy way to read files
* Note: All Methods for getting are higher order functions, not return objects.

Initializing and declaring your object

const FileiFyle = require('fileify-files')
const files = document.querySelector('input[type="file"]').files
window.onload = ()=> {
  const file = new FileiFyle(files[0])
}

The FileiFyle constructor supports an agrument of the Blob type. In this case what is used is the input from an

<input type="file" />
You can give it an id like here:
<input type="file" id="fileInput" />
Javascript:
  const fileInput = document.getElementById('fileInput')
Or you can use a class:
<input type="file" class="fileInput" />
Javascript
const fileInput = document.getElementsByClassName('fileInput')
Or finally you can use the query selector like I do here and did in the origional example:
<input type="file">
Javascript:
const fileInput = document.querySelector('input[type="file"]')

Getting As A DOM Element

When getting the file as a DOM element, you can use the following method:

file.getDomAs('img', img=> {
  /* Do stuff with the DOM element */
})
Note: When getting as an image, it returns an object of the Image() type, therefore you can't use functions like img.setAttribute(...)
The getDomAs(...) method supports the following types:
  • 'img'
  • 'a'
  • 'textNode'
  • 'video'

Getting As Other Types

The file.getAsDataURL(...) retruns a base-64 encoded string of the file.

  file.getAsDataURL(url/* This is a base-64 encoded string */=> {
    /* Do stuff with url */
  })

There are also the methods:

  • getAsBinary(...)
  • getAsArrayBuffer(...)
  • getAsText(...)

About

An easy way to interact with files in javascript using NPM.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published