Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- readerFile(files, input) {
- const img = new Image();
- img.src = window.URL.createObjectURL( files[0] );
- const reader = new FileReader();
- this.setImage(files[0]);
- this.imagePath = files;
- this.onloadReaderFile(reader, img, input, files);
- }
- onloadReaderFile(reader: FileReader, img, input, files) {
- reader.readAsDataURL(files[0]);
- reader.onload = (event) => {
- const width = img.naturalWidth;
- const height = img.naturalHeight;
- window.URL.revokeObjectURL( img.src );
- if (!this.isReaderFileWithSuccess(height, width, input)) {
- return;
- }
- if (!this.isCorrectSizeImage(height, width, input)) {
- return;
- }
- this.isNewImage = true;
- this.imgURL = reader.result;
- };
- }
- isReaderFileWithSuccess(height: number, width: number, input: HTMLInputElement): boolean {
- if (height === 0 && width === 0 ) {
- this.message = 'Erro ao importar o arquivo, tente novamente!';
- input.value = '';
- this.removeImage();
- return false;
- }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement