title: How to abort large file upload with OkHttp?
body: <p>I am using OkHttp 3.1.2. 
  I've created file upload similar to the original recipe which is found here: <a href="https://github.com/square/okhttp/blob/master/samples/guide/src/main/java/okhttp3/recipes/PostMultipart.java" rel="nofollow">https://github.com/square/okhttp/blob/master/samples/guide/src/main/java/okhttp3/recipes/PostMultipart.java</a></p>
  
  <p>I can't find example how to abort an upload of large file upon user request. I mean not how to get the user request but how to tell the OkHttp to stop sending data. 
  So far the only solution that I can imagine is to use custom <code>RequestBody</code>, add an <code>abort()</code> method and override the <code>writeTo()</code> method like this:</p>
  
  <pre><code>public void abort() {
      aborted = true;
  }
  
  @Override
  public void writeTo(BufferedSink sink) throws IOException {
      Source source = null;
      try {
          source = Okio.source(mFile);
          long transferred = 0;
          long read;
  
          while (!aborted &amp;&amp; (read = source.read(sink.buffer(), SEGMENT_SIZE)) != -1) {
              transferred += read;
              sink.flush();
              mListener.transferredSoFar(transferred);
  
          }
      } finally {
          Util.closeQuietly(source);
      }
  }
  </code></pre>
  
  <p>Is there any other way?</p>