🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

generic-file-validator

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

generic-file-validator

This package is designed to check file (MIME) type

4.2.1
latest
Source
npm
Version published
Weekly downloads
8
166.67%
Maintainers
1
Weekly downloads
 
Created
Source

generic-file-validator

What it does?

It checks the file MIME type, and validate it against the extension.

Install

npm i generic-file-validator

Supported media and extension

MediaExtension
image.jpg, .jpeg, .png, .gif, .webp, .tiff, .bmp
audio.mp3, .oga, .wav, .mid, .midi
video.mp4, .ogv, .avi, .mpeg, .webm, .mkv, .3gp
application.doc, .docx, .xls, .xlsx, .ppt, .pptx, .zip, .apk, .pdf

User guide

Props

Props nameDescriptionDefalut valueRequiredExample
fileThe file which you want to validatenulltruefile: file to be validated
mediaThe media type, it will whitelist all the supported extension[]required if 'whitelistExtension' is not passed in the functionmedia: ['image']
whitelistExtensionThe extension you want to whitelist irrespective of media[]required if 'media' is not passed in the functionwhitelistExtension: ['png', 'gif']
blacklistExtensionThe extension you want to blacklist irrespective of media[]falseblacklistExtension: ['tiff', 'pdf']
returnBase64Return base64 of the filetruefalsereturnBase64: false

Usage

Here is the example usage in react app.

import "./App.css";
import fileValidator from "generic-file-validator";

function App() {
  const handleChange = (e) => {
    let file = e.target.files[0];

    fileValidator(
      {
        file: file,
        media: ["image"],
        whitelistExtension: ["jpg", "jpeg"],
        blacklistExtension: ["png"],
      },
      callback
    );
  };

  const callback = (res) => {
    console.log({ res });
  };

  return (
    <div className="App">
      <input type="file" onChange={handleChange} />
    </div>
  );
}

export default App;

https://codesandbox.io/s/generic-file-validator-example-zjlyrm

Keywords

file-validator

FAQs

Package last updated on 21 Jan 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts