Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@bastienmoulia/ngx-file-drop

georgipeltekov22MIT7.0.1TypeScript support: included

npm npm downloads [![Travis](https://img

angular, file drop, folder drop, file upload, folder upload, typescript, drag and drop

readme

npm npm downloads Travis MIT licensed

Overview

An Angular 7 module for simple desktop file and folder drag and drop. This library does not need rxjs-compat.

For Angular 6, 5 and 4 support please use older versions.

This library relies on HTML 5 File API thus IE and Safari are not supported

DEMO

You can check the DEMO of the library

Installation

npm install ngx-file-drop --save

Usage

Importing The 'ngx-file-drop' Module

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpClientModule } from '@angular/common/http';

import { AppComponent } from './app.component';
import { FileDropModule } from 'ngx-file-drop';


@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    FormsModule,
    HttpClientModule,
    FileDropModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

Enabling File Drag

import { Component } from '@angular/core';
import { UploadEvent, UploadFile, FileSystemFileEntry, FileSystemDirectoryEntry } from 'ngx-file-drop';

@Component({
  selector: 'demo-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent {

  public files: UploadFile[] = [];

  public dropped(event: UploadEvent) {
    this.files = event.files;
    for (const droppedFile of event.files) {

      // Is it a file?
      if (droppedFile.fileEntry.isFile) {
        const fileEntry = droppedFile.fileEntry as FileSystemFileEntry;
        fileEntry.file((file: File) => {

          // Here you can access the real file
          console.log(droppedFile.relativePath, file);

          /**
          // You could upload it like this:
          const formData = new FormData()
          formData.append('logo', file, relativePath)

          // Headers
          const headers = new HttpHeaders({
            'security-token': 'mytoken'
          })

          this.http.post('https://mybackend.com/api/upload/sanitize-and-save-logo', formData, { headers: headers, responseType: 'blob' })
          .subscribe(data => {
            // Sanitized logo returned from backend
          })
          **/

        });
      } else {
        // It was a directory (empty directories are added, otherwise only files)
        const fileEntry = droppedFile.fileEntry as FileSystemDirectoryEntry;
        console.log(droppedFile.relativePath, fileEntry);
      }
    }
  }

  public fileOver(event){
    console.log(event);
  }

  public fileLeave(event){
    console.log(event);
  }
}

<div class="center">
    <file-drop dropZoneLabel="Drop files here" (onFileDrop)="dropped($event)" 
    (onFileOver)="fileOver($event)" (onFileLeave)="fileLeave($event)">
        <span>optional content (don't set dropZoneLabel then)</span>
    </file-drop>
    <div class="upload-table">
        <table class="table">
            <thead>
                <tr>
                    <th>Name</th>
                </tr>
            </thead>
            <tbody class="upload-name-style">
                <tr *ngFor="let item of files; let i=index">
                    <td><strong>{{ item.relativePath }}</strong></td>
                </tr>
            </tbody>
        </table>
    </div>
</div>

Parameters

Name Description Example
(onFileDrop) On drop function called after the files are read (onFileDrop)="dropped($event)"
(onFileOver) On drop over function (onFileOver)="fileOver($event)"
(onFileLeave) On drop leave function (onFileLeave)="fileLeave($event)"
accept String of accepted formats accept="png"
dropZoneLabel Text to be displayed inside the drop box dropZoneLabel="Drop files here"
dropZoneClassName Custom style class name(s) to be used on the "drop-zone" area dropZoneClassName="my-style"
contentClassName Custom style class name(s) to be used for the content area contentClassName="my-style"
[disabled] Conditionally disable the dropzone [disabled]="condition"
[showBrowseBtn] Whether browse file button should be shown [showBrowseBtn]="true"
browseBtnClassName Custom style class name(s) to be used for the button browseBtnClassName="my-style"
browseBtnLabel The label of the browse file button browseBtnLabel="Browse files"
multiple Whether multiple or single files are accepted multiple="true"

License

MIT

Change Log

CHANGELOG

  • Ethereum: 0x22d557543ba1f8ac1dadc4eec5ea1b9ae03e0da8
  • Ripple: rJeJTHNyDkqurBBAAUzo4xhJyQo9mhTCJH

changelog

Change Log

16.0.0 (2023-06-19)

  • Update to Angular 16

15.0.0 (2023-03-07)

  • Update to Angular 15

14.0.2 (2022-11-23)

  • Regression fix due to getAsFile

14.0.1 (2022-06-27)

  • Use getAsFile when possible

14.0.0 (2022-06-08)

  • Update to Angular 14

13.0.0 (2021-12-01)

  • Update to Angular 13

12.0.0 (2021-12-01)

  • Update to Angular 12

11.3.0 (2021-11-04)

  • Revert 11.2.0
  • Remove unused interfaces from dom.types

11.2.0 (2021-09-09)

  • On folder/files drop validate accepted file extensions

11.1.0 (2021-04-21)

  • Make FileSystemFileEntry.file() chainable

11.0.1 (2021-02-16)

  • Fix bug with dropEffect not taking into consideration and Outlook problems

11.0.0 (2021-01-29)

  • Update to Angular 11

10.1.1 (2020-11-11)

  • Compile with View Engine

10.0.0 (2020-10-02)

  • Update to Angular 10

9.0.1 (2020-04-15)

  • Add dragenter option

9.0.0 (2020-03-31)

  • Update to Angular 9

8.0.8 (2019-09-26)

  • Add directory parameter

8.0.7 (2019-08-08)

  • Revert previous version due to regression

8.0.6 (2019-08-06)

  • Add readme to the npm package

8.0.5 (2019-08-06)

  • Add directory parameter

8.0.4 (2019-07-17)

  • Lowering node version requirement to LTS version 10 ( again)

8.0.3 (2019-06-28)

  • Lowering node version requirement to LTS version 10

8.0.2 (2019-06-05)

  • Update README

8.0.0 (2019-06-04)

  • Update to Angular 8

6.0.1 (2019-05-08)

  • Add support for multiple attribute changing

6.0.0 (2019-03-11)

  • Code cleanup and consistent naming scheme, removing deprecated code

5.1.0 (2019-03-08)

  • Code cleanup and consistent naming scheme

5.0.6 (2019-02-27)

  • Add accept field

5.0.5 (2019-02-13)

  • Add custom styling properties

5.0.4 (2019-02-04)

  • Add property for browse button label
  • Code optimization and refactoring

5.0.3 (2019-02-01)

  • Fix bug introduced with previous version

5.0.2 (2019-01-23)

  • Add browse file button functionality

5.0.1 (2019-01-18)

  • Support patch-level differences for zone.js
  • Update Readme

5.0.0 (2018-10-22)

  • Update to Angular 7.0.0

4.0.6 (2018-06-19)

  • Bug fixing

4.0.5 (2018-06-19)

  • Fix for big, nested folder structure

4.0.4 (2018-05-16)

  • Clear unused dependencies

4.0.3 (2018-05-15)

  • Loosen Angular-Dependencies

4.0.2 (2018-05-15)

  • Small changes in gitignore

4.0.0 (2018-05-07)

  • Update to Angular 6.0.0

3.0.2 (2018-04-29)

  • Allow drag events to be ignored that originate from document (introduced in 3.0.1) even if using custom styles

3.0.1 (2018-04-25)

  • Conditionally Disable Dropzone and Ignore DragEvents that initiate from within the browser document

3.0.0 (2018-03-15)

  • Added better typescript types

2.0.5 (2018-02-18)

  • Some cleanups

2.0.4 (2018-01-19)

  • Update angular-cli version due to vulnerable dependencies

2.0.3 (2018-01-18)

  • Multiple File-Drops

2.0.2 (2017-12-20)

  • Using a workaround to enable getting files when no webkitGetAsEntry is supported

2.0.1 (2017-11-20)

  • Fix packaging

2.0.0 (2017-11-20)

  • Allow angular 4 & 5 and change the build and packaging process

1.0.18 (2017-10-30)

  • Allow angular 4 & 5

1.0.17 (2017-10-27)

  • Revert Angular 5 changes

1.0.16 (2017-10-27)

  • Prepare upgrade to Angular 5
  • Changes to confirm to the tslint rules

1.0.15 (2017-10-19)

  • Read entries should be called until all dirs are read

1.0.14 (2017-10-19)

  • Add dist folder with .js and .js.map files

1.0.13 (2017-10-13)

  • Fix typo in Readme
  • Add ng-content tag to support nested components within drag/drop region

1.0.12 (2017-09-13)

  • Fix bugs in Safari

1.0.11 (2017-09-13)

  • Fix bug in Safari

1.0.10 (2017-06-21)

  • Check subscription exists before unsubscribing

1.0.9 (2017-06-06)

  • Add onFileOver and onFileLeave functions

1.0.8 (2017-06-03)

  • Remove some not needed dependencies

1.0.7 (2017-06-01)

  • Fix typos in Readme

1.0.5 (2017-05-01)

  • Add Travis CI
  • Update Readme.md

1.0.4 (2017-05-28)

  • Add LICENSE
  • Add DEMO

1.0.3 (2017-05-28)

  • Update npm support

1.0.1 (2017-05-27)

  • Doc update
  • Style changes

1.0.0 (2017-05-25)

  • Initial release