New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

ngx-filezone

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ngx-filezone

File input UI with image and video previews

  • 1.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
decreased by-66.67%
Maintainers
1
Weekly downloads
 
Created
Source

NgxFilezone

Module provides file input UI with image and video previews

see live example

API

Directives

Filezone

Selector: [filezone]
Exported as: filezone
File input interface.
Reacts for users clicks within of all the host element bounding rect (if not restricted by FilezoneButton) and drag-n-drop events carrying files (if not restricted by FilezoneDropArea)

To prevent additional change detection launch all output events of the filezone will be emitted when you subscribe on them only but the 'filechange' event.

Inputs
InputTypeDescription
acceptstringComma-separated list of allowed file extensions or MIME types. Same as <input type="file"/>'s "accept" attribute
sizeLimitstringMax size of files you want to allow ( 3.5MB, 250KB, ect.)
limitOfFilesnumberMaximum number of files you want to allow for user
Outputs
OutputTypeDescription
fileschangeEventEmitter<File[]>Emits every time whether number of files or file sequence has changed
errorsEventEmitter<IFileError[]>Emits if some of files don't fit current restrictions after user's input
docdragbeginEventEmitter<void>Emits after a drag event carrying files has detected on the document
docdragfinishEventEmitter<void>Emits when user drops files or the draging event is leaving the document
dragbeginEventEmitter<void>Same as 'docdragbegin' event but at the host element or restricted drop area
dragfinishEventEmitter<void>Same as 'docdragfinish' event but at the host element or restricted drop area
Properties
NameTypeDescription
acceptstringComma-separated list of allowed file extensions or MIME types or an empty string when not defined
sizeLimitInBytesnumberCurrent limit of size per file or 0 if not defined
limitOfFilesnumberCurrent limit of total amount of files or 0 if not defined
filesFile[]Array of files that currently inside the filezone
windowHasDraggingEventbooleanTrue when user is dragging files over the document
hostHasDraggingEventbooleanTrue when user is dragging files over the host element or restricted drop area
Methods
NameDescription
deleteAllFiles()Deletes all files from the filezone
deleteFile(index: number)Deletes a specified file with given index in filezone
recieveFiles(files: FileList | File[])Gets files to the filezone
replaceFile(index: number)Method will open the file dialog window (has to be fired by users action) and replace a specified file
replaceFileFor(index: number, newFile: File)Method replaces specified file for the new one
sort(from: number, to: number)Move file FROM the given old position in the filezone TO the new position
swap(first: number, second: number)Swap two files at the given indexes in the filezone

FilezoneDropArea

Selector: [fzDropArea]
Constrains area of the filezone which reacts for drag-n-drop events. Must be within the filezone element

FilezoneButton

Selector: [fzButton]
Constrains area of the filezone which reacts for click events. Must be within the filezone element

Pipes

FileSizePipe

Name: filesize
Transforms numeric value representing size of file in bytes to readable string (3 MB, 2.56 KB, ect.)

SafePipe

Name: safeurl
Transforms url string to SafeUrl value

Interfaces

IFileProperties

Interface

DataTypeDescription
durationstringDuration of the file (video or audio type only)
extentionstringExtention of the file
namestringName of the file
resolutionstringResolution of the file (video or image type only)
sizenumberSize of the file in bytes
typestringMedia type of the file
urlstringRepresents the file preview (video or image type only)

IFileError

Interface

DataTypeDescription
errornumberError code
fileFileFile that cause the error

FileErrorCode

Enumeration

ValueDescription
SIZE = 0File size is more than allowed
TYPE = 1Not allowed type of file
COPY = 2The list of files already includes the file
NUMBER = 3Beyond of max number of files

Services

PreviewService

Singletone. Has one method getFileProperties which returns file media data with preview (if availiable and file format supported by modern browsers).

Service has global queue and works with each file you wish to get parameters from sequentially throughout the app

getFileProperties(file: File, width?: number, height?: number) => Promise<IFileProperties>

ParameterDescription
file: FileFile you want to get properties from
width: numberWidth (in pixels) of the preview you want to get. Default 250
height: numberHeight (in pixels) of the preview you want to get. Default equal to width

Utilities

convertFileSizeToString(value: number) => string
Transforms value in bytes to readable string

convertFileSizeToBytes(value: string) => number
Converting string representing size of file (4 MB, 5.35 KB, etc) to numeric value

secondsToTimeString(time: number) => string
Transforms numeric value in seconds to HH:MM:SS string or MM:SS if hours is equal to 0

The convertFileSizeToString and convertFileSizeToBytes functions use base 2 (binary) system where 1KB equal to 1024 bytes

Usage

see live example

  1. Register the module within module you wish
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { NgxFilezoneModule } from 'ngx-filezone';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    BrowserAnimationsModule,
    NgxFilezoneModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }
  1. Create your markup
<div #fz="filezone" filezone 
[accept]="'image/*, .mp4'" [sizeLimit]="'9mb'" [limitOfFiles]="10"
[class.highlighted]="fz.windowHasDraggingEvent">
    <button fzButton>Upload files</button>
    <span>or drop them here</span>
    <section fzDropArea>
        <span>DROP YOUR FILES HERE</span>
    </section>
</div>
  1. Style it
.fz-button {
  border: none;
  background: none;
  padding: 0.5em;
  cursor: pointer;
  font-family: "Segoe UI", sans-serif;
  position: relative;
  color: white;
  border: #858585;
  border-width: 1px;
  border-style: solid;
  background: #707070;
}
.fz-button:focus {
  outline: none;
}
.fz-button:hover {
  background: #111111;
}

.filezone {
  font-family: "Segoe UI", sans-serif;
  color: gray;
  position: relative;
  min-height: 10em;
  min-width: 90vw;
  border: #5c5c5c;
  border-radius: 0.5em;
  border-style: dashed;
  border-width: 3px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}
.filezone.highlighted .fz-drop-area {
  display: flex;
}

.fz-drop-area {
  display: none;
  position: absolute;
  border-radius: 0.3em;
  top: 2px;
  bottom: 2px;
  left: 2px;
  right: 2px;
  background: #426c59;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

Keywords

FAQs

Package last updated on 28 Sep 2020

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc