title: Android WebView: Upload image at Android client side. Cannot get the file type in Server side JavaScript
body: <p>I've tested all the available code on stackOverFlow, but it's still not working.</p>
  
  <p>I use Android 4.4.4 and use WebView to upload image to Server web page, but it fails to get the file type in Server JavaScript code</p>
  
  <pre><code>alert("type:" + input.files[0].type);  
  </code></pre>
  
  <p>If I add the file type check code, this will fail.</p>
  
  <p><strong>I've tested it on desktop (Ubuntu) Chrome, Firefox and on iOS UIWebView. All of them work. The server side will print the file type.
  Only Android 4.4.4 WebView fails.</strong></p>
  
  <p>Server <strong>upload_file.html</strong></p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;script type="text/javascript" language="Javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"&gt;&lt;/script&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;input type='file' class="imageUpload" multiple="true" /&gt;
          &lt;div class="imageOutput"&gt;&lt;/div&gt;
  
          &lt;script language="javascript" type="text/javascript"&gt;
              $images = $('.imageOutput')
  
              $(".imageUpload").change(function(event){
                  readURL(this);
              });
  
              function readURL(input) {
  
                  if (input.files &amp;&amp; input.files[0]) {
                      alert("type:" + input.files[0].type);        
  
                      $.each(input.files, function() {
                          var reader = new FileReader();
                          reader.onload = function (e) {           
                              alert("path:" + e.target.result);
                              $images.append('&lt;img src="'+ e.target.result+'" /&gt;')
                          }
                          reader.readAsDataURL(this);
                      });
                  }
              }
          &lt;/script&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Client (Android) <strong>MainActivity.java</strong></p>
  
  <pre><code>public class MainActivity extends Activity {
  
      private static final int FILE_CHOOSER_RESULT_CODE = 1;
  
      WebView mWebView;
  
      private ValueCallback&lt;Uri&gt; mUploadMessage;
  
      private Context mContext;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          mContext = this;
  
          mWebView = (WebView) findViewById(R.id.webview);
          mWebView.setWebViewClient(new CustomWebViewClient());
  
          mWebView.setWebChromeClient(new WebChromeClient() {
              public void openFileChooser(ValueCallback&lt;Uri&gt; uploadMsg, String acceptType, String capture){
  
  
                  mUploadMessage = uploadMsg;
  
                  MainActivity.this.startActivityForResult(Intent.createChooser(intent, "File Chooser"), FILE_CHOOSER_RESULT_CODE);
  
                  Intent intent = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                  startActivityForResult(intent, FILE_CHOOSER_RESULT_CODE);
  
              }
          });
          WebSettings webSettings = mWebView.getSettings();
          webSettings.setJavaScriptEnabled(true);
          CookieManager.setAcceptFileSchemeCookies(true);
          CookieManager cookieManager = CookieManager.getInstance();
          cookieManager.setAcceptCookie(true);
          mWebView.loadUrl("http://192.168.1.30/upload_file.html");
      }
  
      @Override
      protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
  
          if(requestCode == FILE_CHOOSER_RESULT_CODE) {
              if(mUploadMessage == null)
                  return;
              Uri result = intent == null || resultCode != RESULT_OK ? null : intent.getData();
              Log.d("Ting", "after result:" + result);
              mUploadMessage.onReceiveValue(result);
              mUploadMessage = null;
          }
      }
  
      private class CustomWebViewClient extends WebViewClient {
      }
  </code></pre>
  
  <p>Anyone has ideas how to get the correct file type?</p>
  
  <p>Thanks.
  Eric</p>