title: Android: getting file size of image before sharing it (Intent.ACTION_SEND)
body: <p>I successfully wrote an app, <a href="http://eggie5.com/8-hook-share-picture-via-menu-android">based on this blog post</a>, but simpler, which streams an image over HTTP, using a POST request.</p>
  
  <p>What I can't figure out (after searching the web and crawling inside android SDK docs) is, how do I get the size of the image before I share it?</p>
  
  <p>There is only a possibility to open an input stream that I see in the exampkle and anywhere else:</p>
  
  <pre><code>ContentResolver cr = getContentResolver();
  InputStream is = cr.openInputStream(uri);
  </code></pre>
  
  <p>The given blog post example uses <code>getBytesFromFile(is)</code>, so one could get the size there, but this is <strong>not</strong> a solution. Some images are huge, while android apps are limited in heap space. I want my app to work for all thinkable sizes of images (not a problem when sharing over Wifi).</p>
  
  <p>Therefor, the only option for me is to "forward" the input stream to some HTTP output stream, which I do and which works. But this approach don't give me the image size before sending it.</p>