1.0.3 • Published 4 years ago

get-file-info v1.0.3

Weekly downloads
6
License
MIT
Repository
github
Last release
4 years ago

Overview

A NPM package for getting basic file information like name, size, last modified and type.

Build Status

Installation

npm i get-file-info --save

Setup & Basic Usage

Put the method fileInfo.get() inside the file input function onchange (or any equivalent depending on your framework or library) to get the attach.target.files

const fileInfo = require('get-file-info')

fileInputChange(attach){
    console.log(fileInfo.get(attach.target.files))
    // will show
    {
        name: "TestImage.png",
        size: "1.2 MB",
        type: "image/png",
        lastModifiedDate: "Fri Aug 28 2020 05:44:02 GMT+0000 (Coordinated Universal Time)",
    }
}

Note: This only works for single attachment in a input file type (for now).

Additional info

How it works? When the user put a file inside the input, then the method fileInfo.get() will return the following basic info:

InfoExample
nameTestImage.png
size1KB, 1MB, 1GB and 1TB (depending on the size from bytes)
type"image/png" (If unrecognized file type, then it will return 'Unrecognized file.')
lastModifiedDateFri Aug 28 2020 05:44:02 GMT+0000 (Coordinated Universal Time)

Contribute

Feel free to clone or fork this project: https://github.com/deanilvincent/get-file-info.git

Contributions & pull requests are welcome!

I'll be glad if you give this project a ★ on Github :))

License

This project is licensed under the MIT License - see the LICENSE.md file for details.