Guest User

Untitled

a guest
Jul 17th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. class ImageSnippet {
  2. constructor(public src: string, public file: File) {}
  3. }
  4.  
  5. @Component({
  6. selector: 'bwm-image-upload',
  7. templateUrl: 'image-upload.component.html',
  8. styleUrls: ['image-upload.component.scss']
  9. })
  10. export class ImageUploadComponent {
  11.  
  12. selectedFile: ImageSnippet;
  13.  
  14. constructor(private imageService: ImageService){}
  15.  
  16. processFile(imageInput: any) {
  17. const file: File = imageInput.files[0];
  18. const reader = new FileReader();
  19.  
  20. reader.addEventListener('load', (event: any) => {
  21.  
  22. this.selectedFile = new ImageSnippet(event.target.result, file);
  23.  
  24. this.selectedFile.pending = true;
  25. this.imageService.uploadImage(this.selectedFile.file).subscribe(
  26. (res) => {
  27.  
  28. },
  29. (err) => {
  30.  
  31. })
  32. });
  33.  
  34. reader.readAsDataURL(file);
  35. }
  36. }
Add Comment
Please, Sign In to add comment