Created
November 18, 2019 14:08
-
-
Save ridhof/49fe2974090bfc4d012385f0821d86e0 to your computer and use it in GitHub Desktop.
Upload files on Angular
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
updateFile(foto_param) | |
{ | |
const formData: FormData = new FormData() | |
formData.append('pas_foto', foto_param, foto_param.name); | |
return this.http.post(''.concat( this.config.server_url ,"mahasiswas/beasiswa/berkas/", ""+this.user_id), formData); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<tr> | |
<td> | |
<input type="file" nbInput fullWidth (change)="onPasFotoSelected($event)"> | |
</td> | |
</tr> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
onPasFotoSelected(event) { | |
if(event.target.files.length > 0) | |
{ | |
const reader = new FileReader(); | |
reader.onload = e => this.pas_foto = reader.result; | |
reader.onloadend = (e) => { | |
this.mahasiswa.updateFile(reader.result).subscribe( | |
(data) => { | |
console.log(data) | |
} | |
) | |
} | |
reader.readAsDataURL(event.target.files[0]); | |
this.pas_foto_name = event.target.files[0].name | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment