title: Android download from Azure blob storage results in invalid file
body: <p>From my Android app I try to download from the windows Azure blob storage using the following URL: <a href="http://iclyps.blob.core.windows.net/broadcasts/23_6.mp4" rel="nofollow">http://iclyps.blob.core.windows.net/broadcasts/23_6.mp4</a></p>
  
  <p>The resulting file is corrupt when I download it from within my app. Same error occurs when I download it using the default Browser or Chrome. Also from the Easy Downloader app, the same error occurs. Only a download from my PC or using Firefox Beta from the Android device (or emulator), the file is retrieved correctly.</p>
  
  <p>I use the following code (snippet):</p>
  
  <pre><code>    try {
          HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
  
          //set up some things on the connection
          urlConnection.setRequestMethod("GET");
          urlConnection.setDoOutput(true);
  
          //and connect!
          urlConnection.connect();
  
          bis = new BufferedInputStream(urlConnection.getInputStream(), BUFSIZE);
          bos = new BufferedOutputStream(
                  context.openFileOutput(TMPFILE, Context.MODE_PRIVATE), BUFSIZE);
          /*
           * Read bytes to the buffer in chunks of BUFSIZE bytes until there is nothing more to read.
           * Each chunk is written to the output file.
           */
          byte[] buf = new byte[BUFSIZE];
          int nBytes = 0;
          int tBytes = 0;
          while ((nBytes = bis.read(buf, 0, BUFSIZE)) &gt; 0) {
              bos.write(buf, 0, nBytes);
              tBytes += nBytes;
          }
          if (tBytes == 0) throw new Exception("no bytes received");
          bos.flush();
          MobyLog.d(TAG, "download succeeded: #bytes = " + Integer.toString(tBytes));
          return true;
      } catch (Exception e) {
          MobyLog.e(TAG, "download failed: " + e);
          context.deleteFile(TMPFILE);    // remove possibly present partial file.
          return false;
      } finally {
          if (bis != null) try { bis.close(); } catch (IOException e) {MobyLog.e(TAG, "bis close exception: " + e); };
          if (bos != null) try { bos.close(); } catch (IOException e) {MobyLog.e(TAG, "bos close exception: " + e); };
      }
  </code></pre>
  
  <p>Analyzing the files shows that the first part (about 700K) of the original file is repeated a number of times in the corrupted files, resulting in an invalid mp4 file.</p>
  
  <p>Putting the file on another webserver (Apache/IIS), and downloading the file from that location does result in a correct download.</p>
  
  <p>Has anyone experienced a similar problem performing a download from Azure? Can someone provide a solution?</p>
  
  <p>Cheers,
  Harald...</p>