Note that there are some explanatory texts on larger screens.

plurals
  1. POWebClient UploadFile corrupts binary data
    text
    copied!<p>I am trying to synchronize binary files (photos) from my <code>Monotouch</code> application, running on an <code>iPad</code>, to our <code>PHP</code> server (Windows) using <code>Webclient</code>. The files are being sent and received, but the binary files seem to be corrupt on the server and cannot be viewed.</p> <p>Here is the client side code:</p> <pre><code>static void UploadPhotos() { WebClient client = new WebClient (); client.Headers.Add("Content-Type","application/octet-stream"); string sUri = GetUri(); client.UploadFile (sUri, "POST", "images/test.png"); } </code></pre> <p>And here is the <code>PHP</code> code on the server:</p> <pre><code>&lt;?php $uploadDir = "C:\\uploaddir\\"; foreach ($_FILES as $file_name =&gt; $file_array) { $uploadFile = $uploadDir . $file_array['name']; move_uploaded_file($file_array['tmp_name'], $uploadFile); } ?&gt; </code></pre> <p>Does anyone know why the binary data gets corrupted in the upload and how to fix it?</p> <p><strong>Update:</strong></p> <p>Very strange indeed. It seems the problem I am having affects <code>png</code> images only; <code>jpeg</code> images seem to come across correctly. The <code>jpeg</code> images show the image dimensions correctly in windows explorer on the server and I am able to preview the <code>jpeg</code> images. The <code>jpeg</code> images that I tested were about 90 KB. The <code>png</code> files though are not coming across correctly. In windows explorer the <code>png</code> files don't show the dimensions of the images and cannot be previewed. The <code>png</code> file sizes are larger on the server. So, for example, I use the following <code>png</code> image:</p> <p><a href="http://tuxpaint.org/stamps/stamps/animals/birds/cartoon/tux.png" rel="nofollow">http://tuxpaint.org/stamps/stamps/animals/birds/cartoon/tux.png</a></p> <p>The initial file is 40.2 KB (41236 bytes); after transfer the file size on the server is 45.3 KB (46468 bytes). Anyone got any ideas how this could happen?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload