0
onChange(e) {
      const file = e.target.files[0];
      Storage.put('example.png', file, {
          contentType: 'image/png'
      })
      .then (result => console.log(result))
      .catch(err => console.log(err));
  }

imageupload.html

<input type="file" accept='image/png' onChange={(evt) => this.onChange(evt)}/>

So the following code is in react.How can I write the following code in an angular 6 HTML file? Mainly how to write thisonChange={(evt) => this.onChange(evt)} part in HTML?

For see the original code: https://docs.amplify.aws/lib/storage/upload/q/platform/js#browser-uploads

Toufiqur Rahman
  • 202
  • 3
  • 17

2 Answers2

0

HTML also have the onchange event attribute you can just call the function in the html like: <input type="file" accept='image/png' onchange="onChange(this.value)"/>

0

To copy+paste directly from the SO Post I mentioned;

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

So all we need to do to get this to work with your code is the following:

<input 
    type="file"
    id="file"
    (change)="onChange($event)" 
>

Notice how (change) is now slightly different.

Community
  • 1
  • 1
Dane Brouwer
  • 2,827
  • 1
  • 22
  • 30