title: Why is my binary data bigger after getting it from the webserver?
body: <p>I need to serve a binary file through a web service implemented in Python/Django. The problem is, that when I compare the original file with the transferred file with <em>vbindiff</em> I see trailing bytes on the transferred file, sadly rendering it useless.</p>
  
  <p>The Binary File is accessed saved by a client in Java with:</p>
  
  <pre><code>HttpURLConnection userdataConnection = null;
      URL userdataUrl = null;
      try {
          userdataUrl = new URL("http://localhost:8000/app/vuforia/10");
  
          userdataConnection = (HttpURLConnection) userdataUrl.openConnection();
          userdataConnection.setRequestMethod("GET");
          userdataConnection.setRequestProperty("Content-Type", "application/octet-stream");
          userdataConnection.connect();
  
          InputStream userdataStream = new BufferedInputStream(userdataConnection.getInputStream());
          try (ByteArrayOutputStream fileStream = new ByteArrayOutputStream()) {
              byte[] buffer = new byte[4094];
              while (userdataStream.read(buffer) != -1) {
                  fileStream.write(buffer);
              }
              byte[] fileBytes = fileStream.toByteArray();
              try (FileOutputStream fos = new FileOutputStream("./test.dat")) {
                  fos.write(fileBytes);
              }
          }
      } catch (MalformedURLException e) {
          e.printStackTrace();
      } catch (IOException e) {
          e.printStackTrace();
      }
  </code></pre>
  
  <p>I think that HttpURLConnection.getInputStream only reads the body of the response, or not?</p>
  
  <p>This code serves the data in the backend</p>
  
  <p>in views.py:</p>
  
  <pre><code>if request.method == "GET":
      all_data = VuforiaDatabase.objects.all()
      data = all_data.get(id=version)
      return FileResponse(data.get_dat_bytes())
  </code></pre>
  
  <p>in models.py:</p>
  
  <pre><code>def get_dat_bytes(self):
      return self.dat_upload.open()
  </code></pre>
  
  <p>How do I go about transferring the binary data 1:1?</p>