-1

I using Angular 7 with typescript and my question is: How to upload files from multiple inputs in html like this:

<input type="file" (change)="handleFileInput($event.target.files)">
<input type="file" (change)="handleFileInput($event.target.files)">
<input type="file" (change)="handleFileInput($event.target.files)">

I know about multiple but I can't use it because I need to change the name of each file to value of enum in spring boot app

5
  • Well, you don't make multiple file inputs. You have one input element with multiple attribute to enable the user to upload multiple files. Then you use FormData to append selected files and make a request to the server using HttpClient. Commented Jul 22, 2019 at 7:56
  • @Mateusz Sobczak Is there a reason for not using a single input? Commented Jul 22, 2019 at 8:20
  • @LuisRico because I need to change the name of each file to value of enum in spring boot app Commented Jul 22, 2019 at 8:51
  • Please have a look I hope it's helpful stackoverflow.com/questions/51587241/… Commented Jul 22, 2019 at 9:24
  • 1
    posible duplicate of How to Upload multiple files in Angular 6 with ADDMORE button? Commented Jul 22, 2019 at 9:28

3 Answers 3

0

create one input fields and set multiple params for it.

<input type="file" multiple>
Sign up to request clarification or add additional context in comments.

Comments

0

You don't have to create multiple file input fields. One is enough and You can select multiple files in it to upload.

<input type="file" name="img" multiple>

The multiple attribute is a boolean attribute. When present, it specifies that the user is allowed to enter more than one value in the element. To select multiple files, hold down the CTRL or SHIFT key while selecting.

Comments

0

Using a single input you can still rename each file independently:

  onFileChange(files: FileList) {
     Array.from(files).forEach(file => {
       //ADD CODE TO RENAME THE FILE
      });
 }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.