Giter Site home page Giter Site logo

georgipeltekov / ngx-file-drop Goto Github PK

View Code? Open in Web Editor NEW
289.0 10.0 100.0 5.72 MB

Angular 11 file and folder drop library

License: MIT License

TypeScript 73.22% HTML 7.51% SCSS 13.81% JavaScript 5.45%
angular2 angular4 file-upload file-drop folder upload drop drag ngx 7

ngx-file-drop's Introduction

npm npm downloads Travis MIT licensed

Overview

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

For previous Angular support please use older versions.

This library relies on HTML 5 File API thus IE is 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 { NgxFileDropModule } from 'ngx-file-drop';


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

Enabling File Drag

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

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

  public files: NgxFileDropEntry[] = [];

  public dropped(files: NgxFileDropEntry[]) {
    this.files = files;
    for (const droppedFile of 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">
    <ngx-file-drop dropZoneLabel="Drop files here" (onFileDrop)="dropped($event)" 
    (onFileOver)="fileOver($event)" (onFileLeave)="fileLeave($event)">
        <ng-template ngx-file-drop-content-tmp let-openFileSelector="openFileSelector">
          Optional custom content that replaces the the entire default content.
          <button type="button" (click)="openFileSelector()">Browse Files</button>
        </ng-template>
    </ngx-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"
directory Whether directories are accepted directory="true"
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"
useDragEnter Use dragenter event instead of dragover useDragEnter="true"

License

MIT

Change Log

CHANGELOG

Donate Crypto

  • Bitcoin: 18yJcRSyY7J9K7kHrkNQ2JspLfSgLKWUnh
  • Ethereum: 0xdF1E80c91599CA6d4a8745888e658f45B86b0FEd

ngx-file-drop's People

Contributors

128keaton avatar 5im0n avatar ajuriaa avatar bobbyg603 avatar brolaugh avatar danielsogl avatar dependabot[bot] avatar derektbrown avatar garbanas avatar georgipeltekov avatar hnatt avatar jacobbutton avatar jasminmif avatar jonstelly avatar json-derulo avatar judos avatar kenrick95 avatar maartenmensink avatar p0rsche avatar pturner1989 avatar sabartius avatar sante85 avatar saurye avatar steffenlm avatar swftvsn avatar vtrifonov avatar wclaibor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ngx-file-drop's Issues

File upload

Hi, I was looking for some component to quickly navigate a file system, and yours is really fast!!!
But I can't upload a file :-(
I'm using angular 4 and formData, somethink like this:

formData.append(files, file.fileEntry.resultFile, file.relativePath);

but it seem not work. Can you help?
thanks.

Angular 6 compat

As Angular 6 is almost there, ngx-file-drop should be made compatible with it. The only thing that has to be changed (it seems) is the requirements in the package.json. thx.

Drag and Drop in Safari is opening up File in Same Window.

ngx-file-drop is working good in all browsers except Safari.
Unlike other browsers, when we drag and drop a file in Safari (MacBook), the file is opening in the same window.
Safari version# 9
ngx-file-drop# 1.0.12

Note, i have also tried drag and drop in Demo link provided, in Safari, and its opening up the file.

error TS2451: Cannot redeclare block-scoped variable 'ngDevMode'.

I'm submitting a...

[] Regression (a behavior that used to work and stopped working in a new release)
[x ] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior

From Angular 5.1.3 and before my compilation problem worked fine. Upon upgrading to 5.2.2 I now get ...

ERROR in /ngx-file-drop/node_modules/@angular/core/src/render3/ng_dev_mode.d.ts(9,11)
TS2451: Cannot redeclare block-scoped variable 'ngDevMode'.

ERROR in Error during template compile of 'FileDropModule'
Function expressions are not supported in decorators in 'NgModule'
'NgModule' contains the error at ../@angular/core/core.ts(194,31)
Consider changing the function expression into an exported function.
node_modules/@angular/core/src/render3/ng_dev_mode.d.ts(9,11): error TS2451: Cannot redeclare block-scoped variable 'ngDevMode'.
node_modules/ngx-file-drop/node_modules/@angular/core/src/render3/ng_dev_mode.d.ts(9,11): error TS2451: Cannot redeclare block-scoped variable 'ngDevMode'.

Expected behavior

No compilation error.

Solution

angular/angular-cli#9464
angular/angular#21925

What is the motivation / use case for changing the behavior?
Broken

Environment

Angular version: 5.2.1

For Tooling issues:

  • Node version: 8.2.1
  • Platform: Mac

Others:

Cannot get data refreshed inside fileEntry.file((file: File) => {...} )

Hello,
trying to upload file, and after upload success -> refreshing data

fileEntry.file((file: File) => {
          const formData = new FormData();
          formData.append('property1', '1');
          formData.append('property2, 'false');
          formData.append('Files', file, file.name);

          this._myHttpService.add(formData).subscribe(() => {
            this.toast.info('Document successfully created.');
            this.refreshData();
          });
        });
refreshData() {
    this._myHttpService.getData().subscribe(documents=> {
      this.documents = documents
    });
  }
<file-drop (onFileDrop)="dropped($event)" (onFileOver)="fileOver($event)" (onFileLeave)="fileLeave($event)" customstyle="my-drop-zone">
    <div class="container-fluid">
      <div class="row m-3">
        <div class="col-sm-6">
          <h3>Documents</h3>
          <ul class="list-group">
            <li class="list-group-item" *ngFor="let document of documents">  <-- **this list is not refreshed**
{{document.Name}}
            </li>
          </ul>
        </div>
      </div>
    </div>
  </file-drop>

strange thing about it is, when I'm dragging file over again, list refreshes....

Angular 5.2.7: No Provider for NgZone

I get the following error and i can't figure out why:

FileDropComponent.html:2 ERROR Error: StaticInjectorError(AppModule)[FileComponent -> NgZone]: StaticInjectorError(Platform: core)[FileComponent -> NgZone]: NullInjectorError: No provider for NgZone! at _NullInjector.get (core.js:1002) at resolveToken (core.js:1300) at tryResolveToken (core.js:1242) at StaticInjector.get (core.js:1110) at resolveToken (core.js:1300) at tryResolveToken (core.js:1242) at StaticInjector.get (core.js:1110) at resolveNgModuleDep (core.js:10854) at NgModuleRef_.get (core.js:12087) at resolveDep (core.js:12577)

dependencies:
"@angular/animations": "^5.2.0", "@angular/common": "^5.2.0", "@angular/compiler": "^5.2.0", "@angular/core": "^5.2.0", "@angular/forms": "^5.2.0", "@angular/http": "^5.2.0", "@angular/platform-browser": "^5.2.0", "@angular/platform-browser-dynamic": "^5.2.0", "@angular/router": "^5.2.0", "core-js": "^2.4.1", "ngx-file-drop": "^2.0.5", "primeng": "^5.2.0", "rxjs": "^5.5.6", "zone.js": "^0.8.19"

Angular version: 5.2.7

Argument of type 'UploadFile' is not assignable to parameter of type 'Blob'

Hi,
I'm trying to convert the uploaded image into base64 but continuously getting following error.

Argument of type 'UploadFile' is not assignable to parameter of type 'Blob'

What I'm trying to do is,

public dropped(event: UploadEvent) {

console.log(event);

const files = event.files;

for (const file of event.files) {

  if (file) {

    const reader = new FileReader();

    reader.onload = this._handleReaderLoaded.bind(this);

    reader.readAsBinaryString(file);

  }

}

Any help will be appreciated.

Custom style won't work

If your file-drop component is Encapsulated, how would a foreign class style be applied to the component?
Shouldn't the ViewEncapsulation of the component be set to None?

Unable to update view on drop file

Hi,
I am unable to update the view after reading the file. please find the code below.

public dropped(event: UploadEvent) {
const _t = this;
const imageTypes = ['png', 'svg', 'jpg', 'jpeg', 'jfif', 'jpe'];
this.files = event.files;
for (const file of event.files) {
file.fileEntry.file(info => {
const fileOnlyImage = info.type.split('/')[1].toLowerCase();
if (imageTypes.indexOf(fileOnlyImage) !== -1) {
this.imageFlag = true;//unable to update the imageFlag in view
}
});
}
}

Dependencies too strict

The Dependency-Versions in your package.json are too strict. Angular 6.0.1 is already released but your package strictly requires 6.0.0, so that npm installs 2 Versions of Angular, when using 6.0.1

Cannot drop folder on IE11

Hello, I was trying to upload a folder, in chrome works fine, but in IE the files property of the event comes empty. Can you guys help me? It'd be very nice if I could upload folders in ie too :)

fileDrop($event) {
    this.documentsFromDrop.push(...$event.files); // <- [ ] in ie11
}

In IE 11 is not working

Unfortunately I have to have support for IE11. My Client uses IE11.
At this point there is a bug when a file is dropped into the dropzone.
Can you help me?

ERROR TypeError: Unable to get property 'isFile' of undefined or null reference

Error during template compile

Hi I was testing angular-cli build - Version 6.0.0 and am getting this error...

ERROR in ngx-file-drop\ngx-file-drop.ts(4,2): Error during template compile of 'FileDropModule'
Function calls are not supported in decorators but 'ɵmakeDecorator' was called in 'NgModule'
'NgModule' calls 'ɵmakeDecorator'.

Do you have any suggestions?

Metadata version mismatch for module

Hello,
I am using angular 4 and after following demo it shows following error when I compile my project

ERROR in Error: Metadata version mismatch for module C:/Projects/plugins_dev/IDPortrait/ExtensionContent/angularIDPortrait/node_modules/ngx-file-drop/node_modules/@angular/core/core.d.ts, found version 4, expected 3, resolving symbol FileDropModule in C:/Projects/plugins_dev/IDPortrait/ExtensionContent/angularIDPortrait/node_modules/ngx-file-drop/ngx-file-drop.d.ts, resolving symbol FileDropModule in C:/Projects/plugins_dev/IDPortrait/ExtensionContent/angularIDPortrait/node_modules/ngx-file-drop/ngx-file-drop.d.ts
at syntaxError (C:\Projects\plugins_dev\IDPortrait\ExtensionContent\angularIDPortrait\node_modules@angular\compiler\bundles\compiler.umd.js:1729:34)
at simplifyInContext (C:\Projects\plugins_dev\IDPortrait\ExtensionContent\angularIDPortrait\node_modules@angular\compiler\bundles\compiler.umd.js:24979:23)
at StaticReflector.simplify (C:\Projects\plugins_dev\IDPortrait\ExtensionContent\angularIDPortrait\node_modules@angular\compiler\bundles\compiler.umd.js:24991:13)
at StaticReflector.annotations (C:\Projects\plugins_dev\IDPortrait\ExtensionContent\angularIDPortrait\node_modules@angular\compiler\bundles\compiler.umd.js:24418:41)
at _getNgModuleMetadata (C:\Projects\plugins_dev\IDPortrait\ExtensionContent\angularIDPortrait\node_modules@angular\compiler-cli\src\ngtools_impl.js:138:31)
at _extractLazyRoutesFromStaticModule (C:\Projects\plugins_dev\IDPortrait\ExtensionContent\angularIDPortrait\node_modules@angular\compiler-cli\src\ngtools_impl.js:109:26)
at C:\Projects\plugins_dev\IDPortrait\ExtensionContent\angularIDPortrait\node_modules@angular\compiler-cli\src\ngtools_impl.js:129:27
at Array.reduce (native)
at _extractLazyRoutesFromStaticModule (C:\Projects\plugins_dev\IDPortrait\ExtensionContent\angularIDPortrait\node_modules@angular\compiler-cli\src\ngtools_impl.js:128:10)
at Object.listLazyRoutesOfModule (C:\Projects\plugins_dev\IDPortrait\ExtensionContent\angularIDPortrait\node_modules@angular\compiler-cli\src\ngtools_impl.js:53:22)
at Function.NgTools_InternalApi_NG_2.listLazyRoutes (C:\Projects\plugins_dev\IDPortrait\ExtensionContent\angularIDPortrait\node_modules@angular\compiler-cli\src\ngtools_api.js:91:39)
at AotPlugin._getLazyRoutesFromNgtools (C:\Projects\plugins_dev\IDPortrait\ExtensionContent\angularIDPortrait\node_modules@ngtools\webpack\src\plugin.js:212:44)
at _donePromise.Promise.resolve.then.then.then.then.then (C:\Projects\plugins_dev\IDPortrait\ExtensionContent\angularIDPortrait\node_modules@ngtools\webpack\src\plugin.js:448:24)
at
at process._tickCallback (internal/process/next_tick.js:169:7)

Error after upgrade app to angular 6

After upgrade an app to latest angular, 6, the build started to output:

node_modules/ngx-file-drop/node_modules/@angular/core/src/render3/ng_dev_mode.d.ts(9,11): error TS2451: Cannot redeclare block-scoped variable 'ngDevMode'

Angular 5 support

Hi!

Thank you for an awesome project - keep up the good work!

I get the following error in a completely fresh Angular 5 project: (following your tutorial on install)

Uncaught Error: Template parse errors:
'file-drop' is not a known element:

  1. If 'file-drop' is an Angular component, then verify that it is part of this module.
  2. If 'file-drop' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message. ("

Sorry, if this is not the correct place to report bugs.

Server side file format

How can i handle the file in the server side (nodejs using express) ? If I send the file.fileEntry (as in example) when i log the fileEntry.file i got an undefined. How can i get the file itself ?

ngx-file-drop not working for Firefox

ngx-file-drop is not working in Firefox, its working in Chrome and Edge though. When I drag and drop a file, it is opening up in the browser window.

More files than 100 in a directory

Hi sir @georgipeltekov ,
I have a problem when used your lib.
I see the entries only have max files are 100, if i drag folder have more than the maximum it can read more 100 files. How can i fix it?

Thank you.

How do you drag multiple files?

I want to allow the user to drag and drop up to 5 images. That would be stored in files array.. then uploaded to server.

Current the image object is replaced after every file drop.

Error linking module

Hi,

First of all thanks you.

I'm trying to implement your module but :

frontend     | WARNING in ./node_modules/ngx-file-drop/node_modules/@angular/core/esm5/core.js
frontend     | 6438:15-36 Critical dependency: the request of a dependency is an expression
frontend     |     at ImportLazyContextDependency.getWarnings (/src/app/node_modules/@angular/cli/node_modules/webpack/lib/dependencies/ImportContextDependency.js:28:4)
frontend     |     at Compilation.reportDependencyErrorsAndWarnings (/src/app/node_modules/@angular/cli/node_modules/webpack/lib/Compilation.js:677:24)
frontend     |     at Compilation.finish (/src/app/node_modules/@angular/cli/node_modules/webpack/lib/Compilation.js:535:9)
frontend     |     at applyPluginsParallel.err (/src/app/node_modules/@angular/cli/node_modules/webpack/lib/Compiler.js:512:17)
frontend     |     at /src/app/node_modules/tapable/lib/Tapable.js:289:11
frontend     |     at _addModuleChain (/src/app/node_modules/@angular/cli/node_modules/webpack/lib/Compilation.js:481:11)
frontend     |     at processModuleDependencies.err (/src/app/node_modules/@angular/cli/node_modules/webpack/lib/Compilation.js:452:13)
frontend     |     at _combinedTickCallback (internal/process/next_tick.js:131:7)
frontend     |     at process._tickCallback (internal/process/next_tick.js:180:9)
frontend     | 
frontend     | WARNING in ./node_modules/ngx-file-drop/node_modules/@angular/core/esm5/core.js
frontend     | 6458:15-102 Critical dependency: the request of a dependency is an expression
frontend     |     at ImportLazyContextDependency.getWarnings (/src/app/node_modules/@angular/cli/node_modules/webpack/lib/dependencies/ImportContextDependency.js:28:4)
frontend     |     at Compilation.reportDependencyErrorsAndWarnings (/src/app/node_modules/@angular/cli/node_modules/webpack/lib/Compilation.js:677:24)
frontend     |     at Compilation.finish (/src/app/node_modules/@angular/cli/node_modules/webpack/lib/Compilation.js:535:9)
frontend     |     at applyPluginsParallel.err (/src/app/node_modules/@angular/cli/node_modules/webpack/lib/Compiler.js:512:17)
frontend     |     at /src/app/node_modules/tapable/lib/Tapable.js:289:11
frontend     |     at _addModuleChain (/src/app/node_modules/@angular/cli/node_modules/webpack/lib/Compilation.js:481:11)
frontend     |     at processModuleDependencies.err (/src/app/node_modules/@angular/cli/node_modules/webpack/lib/Compilation.js:452:13)
frontend     |     at _combinedTickCallback (internal/process/next_tick.js:131:7)
frontend     |     at process._tickCallback (internal/process/next_tick.js:180:9)
frontend     |                           
client?d28c:43 ./node_modules/ngx-file-drop/node_modules/@angular/core/esm5/core.js
6438:15-36 Critical dependency: the request of a dependency is an expression
Unexpected value 'FileDropModule' imported by the module 'AppModule'. Please add a @NgModule annotation. 

Package.json

{
    "name": "project",
    "version": "0.0.0",
    "license": "MIT",
    "scripts": {
        "ng": "ng",
        "start": "ng serve -H 0.0.0.0 -port 4903 --disable-host-check",
        "build": "ng build",
        "test": "ng test",
        "lint": "ng lint",
        "e2e": "ng e2e"
    },
    "private": true,
    "dependencies": {
        "@angular/animations": "^4.4.6",
        "@angular/cdk": "^2.0.0-beta.12",
        "@angular/common": "^4.4.6",
        "@angular/compiler": "^4.4.6",
        "@angular/core": "^4.4.6",
        "@angular/flex-layout": "^2.0.0-beta.10-4905443",
        "@angular/forms": "^4.4.6",
        "@angular/http": "^4.4.6",
        "@angular/material": "^2.0.0-beta.12",
        "@angular/platform-browser": "^4.4.6",
        "@angular/platform-browser-dynamic": "^4.4.6",
        "@angular/router": "^4.4.6",
        "@ng-bootstrap/ng-bootstrap": "^1.0.0-beta.5",
        "@ngx-translate/core": "^8.0.0",
        "@types/jstree": "^3.3.35",
        "@types/toastr": "^2.1.35",
        "angular-oauth2-oidc": "^2.1.8",
        "animate.css": "^3.5.2",
        "bootstrap": "^3.3.7",
        "chart.js": "^2.7.1",
        "core-js": "^2.5.1",
        "crypto-js": "^3.1.9-1",
        "enhanced-resolve": "^3.4.1",
        "font-awesome": "^4.7.0",
        "hammerjs": "^2.0.8",
        "jquery": "^3.2.1",
        "jquery-slimscroll": "^1.3.8",
        "jquery-sparkline": "^2.4.0",
        "jstree": "^3.3.4",
        "jvectormap": "^1.2.2",
        "metismenu": "^2.7.1",
        "ngx-bootstrap": "^2.0.0-beta.8",
        "ngx-file-drop": "^2.0.1",
        "peity": "^3.2.1",
        "rxjs": "^5.5.2",
        "simplebar": "^2.5.0",
        "snazzy-info-window": "^1.1.0",
        "toastr": "^2.1.2",
        "webpack": "^3.8.1",
        "zone.js": "^0.8.18"
    },
    "devDependencies": {
        "@angular/cli": "1.3.1",
        "@angular/compiler-cli": "^4.4.6",
        "@angular/language-service": "^4.4.6",
        "@types/googlemaps": "^3.29.1",
        "@types/jasmine": "~2.5.53",
        "@types/jasminewd2": "~2.0.2",
        "@types/node": "^6.0.90",
        "codelyzer": "~3.1.1",
        "jasmine-core": "~2.6.2",
        "jasmine-spec-reporter": "~4.1.0",
        "karma": "~1.7.0",
        "karma-chrome-launcher": "~2.1.1",
        "karma-cli": "~1.0.1",
        "karma-coverage-istanbul-reporter": "^1.2.1",
        "karma-jasmine": "~1.1.0",
        "karma-jasmine-html-reporter": "^0.2.2",
        "node-sass": "^4.6.0",
        "protractor": "~5.1.2",
        "raw-loader": "^0.5.1",
        "sass-loader": "^6.0.6",
        "ts-node": "~3.2.0",
        "tslint": "~5.3.2",
        "typescript": "~2.3.3"
    }
}

appmodule

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import {Http, HttpModule} from '@angular/http';
import { CommonModule } from '@angular/common';
import { RouterModule } from '@angular/router';
import { LocationStrategy, HashLocationStrategy, PathLocationStrategy } from '@angular/common';

import { ROUTES } from './app.routes';
import { AppComponent } from './app.component';

// App views
import {AppviewsModule} from './_views/appviews.module';

// App modules/components
import {LayoutsModule} from './_components/common/layouts/layouts.module';

import {HttpClientModule} from '@angular/common/http';
import {AuthGuard} from './_guards/auth.guard';

import {OAuthService, UrlHelperService} from 'angular-oauth2-oidc';
import {SecurityService} from './_services/security.service';

import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
import {ItConstellationModule} from './_views/it-constellation/it-constellation.module';
import { FileDropModule } from 'ngx-file-drop';
@NgModule({
    declarations: [
        AppComponent,

    ],
    imports: [
        BrowserModule,
        FormsModule,
        CommonModule,
        HttpModule,
        LayoutsModule,
        ItConstellationModule,
        AppviewsModule,
        HttpClientModule,
      FileDropModule,
      RouterModule.forRoot(ROUTES),
        BrowserAnimationsModule
        /*RouterModule.forRoot(ROUTES, {
            enableTracing: /localhost/.test(document.location.host)
        })*/
    ],
    providers: [
        {provide: LocationStrategy, useClass: PathLocationStrategy},
        AuthGuard,
        OAuthService,
        UrlHelperService,
        SecurityService
    ],
    bootstrap: [AppComponent]
})
export class AppModule { }

Thanks for your help.

Template parse errors: 'file-drop' is not a known element:

compiler.es5.js:1694 Uncaught Error: Template parse errors:
'file-drop' is not a known element:

  1. If 'file-drop' is an Angular component, then verify that it is part of this module.
  2. If 'file-drop' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message. ("
    hardware
[ERROR ->]) at JitCompiler.webpackJsonp.../../../compiler/@angular/compiler.es5.js.JitCompiler._compileComponents (compiler.es5.js:26913) at compiler.es5.js:26800 at Object.then (compiler.es5.js:1683) at JitCompiler.webpackJsonp.../../../compiler/@angular/compiler.es5.js.JitCompiler._compileModuleAndComponents (compiler.es5.js:26799) at JitCompiler.webpackJsonp.../../../compiler/@angular/compiler.es5.js.JitCompiler.compileModuleAsync (compiler.es5.js:26728)

I got this error.Help me to figure out on what mistake i did...
Thank you in Advance.

Dragging text to drop zone produces error: Cannot read property 'isFile' of null

ERROR TypeError: Cannot read property 'isFile' of null

Tested on Chrome latest by dragging text from my website to the drop zone.

The code where the error is present:

    for (var i = 0; i < length; i++) {
      var entry;
      if (event.dataTransfer.items) {
        if (event.dataTransfer.items[i].webkitGetAsEntry) {
          entry = event.dataTransfer.items[i].webkitGetAsEntry();
        }
      } else {
        if (event.dataTransfer.files[i].webkitGetAsEntry) {
          entry = event.dataTransfer.files[i].webkitGetAsEntry()
        }
      }

      if (entry.isFile) { // <--- Error occurs here
        const toUpload: UploadFile = new UploadFile(entry.name, entry);
        this.addToQueue(toUpload);
      } else if (entry.isDirectory) {
        this.traverseFileTree(entry, entry.name);
      }
    }

Solution:

Check if entry is null before checking entry.isFile

Use really only the customStyle if it is given

I have a lot of html inside the file-drop element and it gets styled because of this content class, my solution:

//file-drop.component.html:4
<div [class.content]="!customstyle">

i could not create a pull request (i tried but i may be too inexperienced in github) but i would be pleased if you could change this.

Adding Add button

Hi, great work on this component.

A suggestion for you to add in the Add Files button.
Not all users may want to drag though.

Broken demo

Using Angular 6 your demo appears to be broken

Does not work with Angular 5

ERROR in ./node_modules/ngx-file-drop/lib/ngx-drop/index.ts
Module build failed: Error: TypeScript compilation failed.

Metadata version mismatch for module

hello , i am using CookieSevice , first i have installl them by
npm install ngx-cookie --save
then i created cookie backend for fake token generating , now i am getting error below :--

Error: Metadata version mismatch for module F:/edcertsWallet/node_modules/ngx-cookie/index.d.ts, found version 4, expected 3, resolving symbol AppModule in F:/edcertsWallet/src/app/app.module.ts, resolving symbol AppModule in F:/edcertsWallet/src/app/app.module.ts, resolving symbol AppModule in F:/edcertsWallet/src/app/app.module.ts
at syntaxError (F:\edcertsWallet\node_modules@angular\compiler\bundles\compiler.umd.js:1729:34)
at simplifyInContext (F:\edcertsWallet\node_modules@angular\compiler\bundles\compiler.umd.js:25111:23)
at StaticReflector.simplify (F:\edcertsWallet\node_modules@angular\compiler\bundles\compiler.umd.js:25123:13)
at StaticReflector.annotations (F:\edcertsWallet\node_modules@angular\compiler\bundles\compiler.umd.js:24553:41)
at _getNgModuleMetadata (F:\edcertsWallet\node_modules@angular\compiler-cli\src\ngtools_impl.js:138:31)
at _extractLazyRoutesFromStaticModule (F:\edcertsWallet\node_modules@angular\compiler-cli\src\ngtools_impl.js:109:26)
at Object.listLazyRoutesOfModule (F:\edcertsWallet\node_modules@angular\compiler-cli\src\ngtools_impl.js:53:22)
at Function.NgTools_InternalApi_NG_2.listLazyRoutes (F:\edcertsWallet\node_modules@angular\compiler-cli\src\ngtools_api.js:91:39)
at AotPlugin._getLazyRoutesFromNgtools (F:\edcertsWallet\node_modules@ngtools\webpack\src\plugin.js:241:66)
at _donePromise.Promise.resolve.then.then.then.then.then (F:\edcertsWallet\node_modules@ngtools\webpack\src\plugin.js:495:24)
at process._tickCallback (internal/process/next_tick.js:103:7)

Bug on Safari

Hey! The module works great in all other browsers, but in Safari I am getting an error when I drag&drop the files over. The Errors is: ERROR – TypeError: undefined is not an object (evaluating 'event.dataTransfer.items.length') — file-drop.component.ts:74 and I can't figure out what causes the error.

#Edit - I've set console.log(event) on file-drop.component.ts:71 and it logs the Mouse event, The problem is I guess that in Safari the event.dataTransfer.items property does not exist. Screen shot: http://prntscr.com/gkpk9f

Multiple file-drops on same page

I can't get multiple instances of <file-drop> on the same page to work correctly.

The onFileDrop event only fires for the last instance of <file-drop>.

Package contains root folder instead of dist folder

@georgipeltekov I just installed the package 2.0.0 the version.

It seems that the root was packaged and instead of the dist folder.

the publish command should be npm publish dist so that it only packages the dist folder and not the entire root folder of the repository.

I noticed you reverted a change in the readme.md file

import { FileDropModule } from 'ngx-file-drop/src/lib/ngx-drop';

but it should be

import { FileDropModule } from 'ngx-file-drop';

that doesn't work due incorrect packaging.

Problem with fileupload

Hello,

sorry I have a problem during fileupload with this module.
After Drop file, the property "type" of file is null and i saw only information about name,size and lastModified... how can access to entire File with your module?

This is my code, it's correct? :

public dropped(event: UploadEvent) {
var input = new FormData();
if (event.files[0].fileEntry.file) {
event.files[0].fileEntry.file(function (fileData) {
input.append('uploadedFile', fileData);
});
}
//this provide a rest multipart call
this.inserisciExcel(input);
}

Thanks a lot for your fast help!!
Max

file-drop' is not a known element

file-drop' is not a known element:

  1. If 'file-drop' is an Angular component, then verify that it is part of this module.
    .......

I am using angualr 5
"dependencies": { "@angular/animations": "^5.2.10", "@angular/common": "^5.2.0", "@angular/compiler": "^5.2.0", "@angular/core": "^5.2.0", "@angular/forms": "^5.2.0", "@angular/http": "^5.2.0", "@angular/platform-browser": "^5.2.0", "@angular/platform-browser-dynamic": "^5.2.0", "@angular/router": "^5.2.0", "angular-font-awesome": "^3.1.2", "bootstrap": "^4.1.0", "cfenv": "^1.0.4", "core-js": "^2.4.1", "express": "^4.15.0", "font-awesome": "^4.7.0", "ngx-file-drop": "^3.0.0", "rxjs": "^5.5.6", "zone.js": "^0.8.19"
and using version 3.0.0

I have added to app.module.ts too but still facing error

Question about the new disable functionality added in #55

Hi,

the new addition is wonderful, but we need custom style and the global disable functionality.

The code that initiates the listeners in component constructor are inside

if (!this.customstyle) {

so I can't have custom style and disable the drag events that originate from within the document. Is this itentional and why?

Uploading a file to a web api

I am trying to post the file to my Web API but I am having some issues. I have this method in my service:

  public uploadFile(file: UploadFile): Observable<string> {
    const endpoint = 'uploadfile';
    const url = this.uri + endpoint;

    let input = new FormData();
    input.append("file", file.fileEntry.file);

    return this.http.post(url, input).map(res => res.json());
  }

I am hitting the break point in my web api but I think i am getting the wrong data. I believe it has something to do with the data that I am passing.

What do I need to pass here:

input.append("file", file.fileEntry.file);

Thanks

Compile .js and .js.map files

I'm trying to use this in an Ionic app but when I run it I get
Uncaught Error: Module build failed: Error: ENOENT: no such file or directory, open '/path/to/ngx-file-drop/lib/ngx-drop/index.js.map'

Is there anything I can tweak in tsconfig.json to get it to generate these two files? I've tried building it but no luck.
Thanks.

customstyle having no effect on file-drop selector

Tried this in my current project and spun up another quick project to see if it was isolated to my environment via angular-cli. Both of them have the same results. The "drop zone" has no border and collapses into having no width - if you attempt to override the style, it will become virtually unusable to the user. I even tried overriding your drop-zone default CSS class and using !important. Any thoughts on what I could be doing wrong?

app.component.ts:

...

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

app.component.html:

<file-drop customstyle="random-custom-class">
</file-drop>

app.component.scss:

.random-custom-class {
    border: 5px solid #00FF00; /* Something obviously different than the default */
}

Inconsistent behavior when (edit: Dragging folders from networked drives)

Screenshot of issue

The above attachment is a result of me dragging the exact same folder several times. The dragged folder is a network drive if that makes a difference.

I also notice that sometimes the uploadFile queue is not fully empty when a new dropped event occurs. This was tested by dragging the same large folder as shown above, then dragging an empty folder afterwards. The empty folder drop event contained many files from the previous event.

Tested on:
Chrome 62
NodeJS 8.6.0
npm 5.3.0
Angular 4 CLI 1.5.2

Get File Base64 Format

Is there is a way to get the file content in Base64 format from the file object ???
This is the info i get from the library .. There is no any info describing the file content it self

File(60005) {name: "profile (4).jpg", lastModified: 1511451066787, lastModifiedDate: Thu Nov 23 2017 17:31:06 GMT+0200 (Egypt Standard Time), webkitRelativePath: "", size: 60005, …}
lastModified:1511451066787
lastModifiedDate:Thu Nov 23 2017 17:31:06 GMT+0200 (Egypt Standard Time) {}
name:"profile (4).jpg"
size:60005
type:"image/jpeg"
webkitRelativePath:""

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.