Skip to content

Instantly share code, notes, and snippets.

@Jerga99
Created July 17, 2018 21:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jerga99/b69eef9899f8a758083a301e3bdfdca6 to your computer and use it in GitHub Desktop.
Save Jerga99/b69eef9899f8a758083a301e3bdfdca6 to your computer and use it in GitHub Desktop.
class ImageSnippet {
constructor(public src: string, public file: File) {}
}
@Component({
selector: 'bwm-image-upload',
templateUrl: 'image-upload.component.html',
styleUrls: ['image-upload.component.scss']
})
export class ImageUploadComponent {
selectedFile: ImageSnippet;
constructor(private imageService: ImageService){}
processFile(imageInput: any) {
const file: File = imageInput.files[0];
const reader = new FileReader();
reader.addEventListener('load', (event: any) => {
this.selectedFile = new ImageSnippet(event.target.result, file);
this.selectedFile.pending = true;
this.imageService.uploadImage(this.selectedFile.file).subscribe(
(res) => {
},
(err) => {
})
});
reader.readAsDataURL(file);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment