File Upload In Angular?

前端 未结 14 2530
执念已碎
执念已碎 2020-11-22 08:10

I know this is very a general question but I am failing to upload a file in Angular 2. I have tried

1) http://valor-software.com/ng2-file-upload/ and

2) h

14条回答
  •  醉梦人生
    2020-11-22 08:58

    Today I was integrated ng2-file-upload package to my angular 6 application, It was pretty simple, Please find the below high-level code.

    import the ng2-file-upload module

    app.module.ts

        import { FileUploadModule } from 'ng2-file-upload';
    
        ------
        ------
        imports:      [ FileUploadModule ],
        ------
        ------
    

    Component ts file import FileUploader

    app.component.ts

        import { FileUploader, FileLikeObject } from 'ng2-file-upload';
        ------
        ------
        const URL = 'http://localhost:3000/fileupload/';
        ------
        ------
    
         public uploader: FileUploader = new FileUploader({
            url: URL,
            disableMultipart : false,
            autoUpload: true,
            method: 'post',
            itemAlias: 'attachment'
    
            });
    
          public onFileSelected(event: EventEmitter) {
            const file: File = event[0];
            console.log(file);
    
          }
        ------
        ------
    

    Component HTML add file tag

    app.component.html

     
    

    Working Online stackblitz Link: https://ng2-file-upload-example.stackblitz.io

    Stackblitz Code example: https://stackblitz.com/edit/ng2-file-upload-example

    Official documentation link https://valor-software.com/ng2-file-upload/

提交回复
热议问题