How can I get the name of the file I'm uploading

Emanuel

I'm using angular-file-uploader (https://www.npmjs.com/package/angular-file-uploader) to upload files and it works fine, but I can't find a way to get the filename, I want something like assign it to a variable so I can use to download it later.

I got a component with the following html template:

<angular-file-uploader 
    [config]="afuConfig"
    (ApiResponse)="DocUpload($event)">
</angular-file-uploader>

and TypeScript:

this.afuConfig = {
    uploadAPI: {
        url:"http://localhost:3000/api/containers/container/upload",
    }
};

DocUpload(res){
    console.log(res);
    //I want something like this..
    //console.log(somehow.getFileName())
}
Philipp Kief

You have to add a selector to the template called fileUpload1 for example:

<angular-file-uploader
  #fileUpload1
  [config]="afuConfig"
  (ApiResponse)="DocUpload($event)"
></angular-file-uploader>

In the TypeScript part of your component you add a ViewChild property to the class:

@ViewChild('fileUpload1')
private fileUpload1: AngularFileUploaderComponent;

And finally you can get the file name in the DocUpload function like this:

DocUpload(res) {
  console.log(this.fileUpload1.allowedFiles[0].name);
}

The allowedFiles attribute is an array of all selected files. If you want the first one you have to use allowedFiles[0] and then read the name via the name attribute.

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

How can I expand both a variable name and a wildcard in a file name?

분류에서Dev

How can I make a integer for every name in a txt file?

분류에서Dev

How can I hide the file name in full screen mode?

분류에서Dev

How do I get the name of Postscript file object?

분류에서Dev

How can i get number of entries and column name in a unique select?

분류에서Dev

uploading a file but did not get a file name

분류에서Dev

RadGrid attachmentcolumn get name of file before uploading

분류에서Dev

How can I get a part of text file by terminal

분류에서Dev

How can I get the contents of a file one line at a time?

분류에서Dev

How can I get "RHEL 7.0 vmlinux" file?

분류에서Dev

How can I get the extension(s) of a file based on its content?

분류에서Dev

How can I get the root terminal to add myself into sudoers file so that I can act as root?

분류에서Dev

How can I get a RejectedExecutionException

분류에서Dev

How can I get a solution for this?

분류에서Dev

How can i use $_POST if the name is a variable?

분류에서Dev

Is there anyway I can get the time of cached file?

분류에서Dev

How can I rename a file containing "&" in its name in kubuntu using Dolphin or terminal?

분류에서Dev

How can I get $_GET values to a variable

분류에서Dev

How do I get a DLL or EXE name from a C# project file?

분류에서Dev

Why are the name repeating in my array, and how would i get a txt file to sort

분류에서Dev

How can i get cakephp current model's foreign key column name?

분류에서Dev

How can I tell what version of Linux I'm using?

분류에서Dev

How can I view file header information?

분류에서Dev

How can I save the last command to a file?

분류에서Dev

How can I wait for the write of a file?

분류에서Dev

How can I copy a text file into another?

분류에서Dev

How can i replace particular characters in a file

분류에서Dev

How can I test for a file having a value?

분류에서Dev

How can I check if a gzipped file is empty?

Related 관련 기사

  1. 1

    How can I expand both a variable name and a wildcard in a file name?

  2. 2

    How can I make a integer for every name in a txt file?

  3. 3

    How can I hide the file name in full screen mode?

  4. 4

    How do I get the name of Postscript file object?

  5. 5

    How can i get number of entries and column name in a unique select?

  6. 6

    uploading a file but did not get a file name

  7. 7

    RadGrid attachmentcolumn get name of file before uploading

  8. 8

    How can I get a part of text file by terminal

  9. 9

    How can I get the contents of a file one line at a time?

  10. 10

    How can I get "RHEL 7.0 vmlinux" file?

  11. 11

    How can I get the extension(s) of a file based on its content?

  12. 12

    How can I get the root terminal to add myself into sudoers file so that I can act as root?

  13. 13

    How can I get a RejectedExecutionException

  14. 14

    How can I get a solution for this?

  15. 15

    How can i use $_POST if the name is a variable?

  16. 16

    Is there anyway I can get the time of cached file?

  17. 17

    How can I rename a file containing "&" in its name in kubuntu using Dolphin or terminal?

  18. 18

    How can I get $_GET values to a variable

  19. 19

    How do I get a DLL or EXE name from a C# project file?

  20. 20

    Why are the name repeating in my array, and how would i get a txt file to sort

  21. 21

    How can i get cakephp current model's foreign key column name?

  22. 22

    How can I tell what version of Linux I'm using?

  23. 23

    How can I view file header information?

  24. 24

    How can I save the last command to a file?

  25. 25

    How can I wait for the write of a file?

  26. 26

    How can I copy a text file into another?

  27. 27

    How can i replace particular characters in a file

  28. 28

    How can I test for a file having a value?

  29. 29

    How can I check if a gzipped file is empty?

뜨겁다태그

보관