akveo / nebular

:boom: Customizable Angular UI Library based on Eva Design System :new_moon_with_face::sparkles:Dark Mode
https://akveo.github.io/nebular
MIT License
8.06k stars 1.51k forks source link

I cant see any file uploader components in nebular . do you have any? #2285

Open sujeshshivan opened 4 years ago

sujeshshivan commented 4 years ago

Issue type I'm submitting a feature request

Issue description Current behavior: There is no file uploader

augustoicaro commented 4 years ago

Hello @sujeshshivan.

Nebular doesn't have yet a file uploader module, but you can use the prototype described in a not accepted pull request by @lexzhukov as I did. If you want to see how I applied this prototype component in my ngx-admin template, take a look in these two commits:

  1. Initial implementation
  2. Add drag'n'drop feature

Steps to use:

  1. Import NbFileUploaderModule in your desired module
  2. In the component that you want add the file uploader use:
    // component.ts
    export class MyComponent  implements OnInit{
    allowedMimeType: string[] =  ['image/png','image/jpg'];  // Change to what file types you need
    fileTypesAllowed: string[];
    maxFileSize = 2;  // Change to max file size in mb
    options: NbFileUploaderOptions;
    ...
    ngOnInit() {
    this.fileTypesAllowed = this.allowedMimeType.map((fileType: string) =>
      fileType.substring(fileType.lastIndexOf('/') + 1, fileType.length)
    );
    options = {
      url: 'http://localhost:3000',
      multiple: false,
      directory: false,
      showUploadQueue: true,
      allowedFileTypes: this.allowedMimeType,
      filter: {
        fn: (item: File) => {
          if (item.size / 1024 / 1024 > this.maxFileSize) {
            return false;
          }
          const itemType =
            item.name.substring(
              item.name.lastIndexOf('.') + 1,
              item.name.length
            ) || item.name;
          if (!this.fileTypesAllowed.includes(itemType)) {
            return false;
          }
          return true;
        },
      },
    };
    }
    ...
    <!-- component.html -->
    ...
    <nb-file-uploader
    [options]="options"
    [isFileDrop]="true"
    buttonLabel="Browse"
    dropAreaLabel="Drag files here or"
    dropAreaFileChooserLabel="browse to upload"
    ></nb-file-uploader>
    ...

P.S. In my implementation, drag'n'drop feature isn't reacting to nebular themes.