title: How to set image upload size limit (for example 2mb maximum) in Angular
body: <p>we are trying to set a limit on the size of the image like maximum it should be 2mb. We are using ng2-file-upload. You can see the code in the bellow:</p>
  
  <pre><code>uploader: FileUploader = new FileUploader({
      url: URL,
      disableMultipart: true
    });
  ...
  ...
  OnFileSelected(event) {
      const file: File = event[0];
  
      this.ReadAsBase64(file)
        .then(result =&gt; {
          this.selectedFile = result;
        })
        .catch(err =&gt; console.log(err));
    }
  
    Upload() {
      if (this.selectedFile) {
        this.usersService.AddImage(this.selectedFile).subscribe(
          data =&gt; {
            this.socket.emit('refresh', {});
            console.log(data);
          },
          err =&gt; console.log(err)
        );
      }
    }
  
    ReadAsBase64(file): Promise&lt;any&gt; {
      const reader = new FileReader();
      const fileValue = new Promise((resolve, reject) =&gt; {
        reader.addEventListener('load', () =&gt; {
          resolve(reader.result);
        });
  
        reader.addEventListener('error', event =&gt; {
          reject(event);
        });
  
        reader.readAsDataURL(file);
      });
  
      return fileValue;
    }
  </code></pre>
  
  <p>Where and how can we set that limit on the image?</p>