title: Image compression on uiwebview html form
body: <p>I have a simple html form, with an input of type image:</p>
  
  <pre><code>    ...
      &lt;form action="new.php" method="POST" enctype="multipart/form-data"&gt;
          &lt;input type="text" name="text" placeholder="text"&gt;&lt;br&gt;&lt;br&gt;
          &lt;input type="file" name="file" accept="image/*;capture=camera"&gt;&lt;br&gt;&lt;br&gt;
          &lt;input type="submit" value="Submit"&gt;
      &lt;/form&gt;
      ...
  </code></pre>
  
  <p>In an iOS app I've implemented a <code>UIWebView</code>, this webview loads the html provided before.</p>
  
  <p>In this form I can add a text and a file (an image in this case) but what I want to do is pre-process the image, if the image is to big then call a method that returns a smaller image.</p>
  
  <p>I've tried to intercept the request with <code>-webView:shouldStartLoadWithRequest:navigationType:</code> and modify the NSData from the request body/bodyStream but it seems too messy.</p>
  
  <p>I've also tried using <code>javascript</code> to call native Objc methods using a custom <code>URI</code>:</p>
  
  <pre><code>function selectFile() { 
      window.location = "testapp://selectFile";
  }
  </code></pre>
  
  <p>And the app part:</p>
  
  <pre><code>-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
      NSURL *url = request.URL;
      if ([[url scheme] isEqualToString:@"testapp"]) {
          [self openCustomFile];
          return NO;
      }
      return YES;
  }
  </code></pre>
  
  <p>Using this I can call my own file chooser and do whatever I want to the <code>UIImage</code>, but my problem now is that I don't know how can I attach this to the form on the <code>UIWebView</code>, as far as I know, that is not possible.</p>
  
  <p>So, is there any way to preprocess an image to be attached on a <code>UIWebView</code> form?</p>