Sending an image to a server with Arduino

Hello,

I am currently trying to send a jpeg picture (taken by a serial TTL camera) over WiFi (but could be over Ethernet) to a server running on my computer. I use the Arduino Uno board + a CC3000 chip that I know works perfectly. This is the code I am using on the Arduino side:

      uint32_t len = jpglen + 177; // 177 is the content without the image data  
      client.println(F("POST /ohs/camera.php HTTP/1.1"));
      client.println(F("Host: 192.168.0.14:8888"));
      client.println(F("Content-type: multipart/form-data, boundary=UH3xBZZtzewr09oPP"));
      client.print(F("Content-Length: "));
      client.println(len);
      client.println(); // 2
      client.println(F("--UH3xBZZtzewr09oPP")); // 21
      client.println(F("content-disposition: form-data; name=\"picture\"; filename=\"cam.jpg\"")); // 68
      client.println(F("Content-Type: image/jpeg")); // 26
      client.println(F("Content-Transfer-Encoding: binary")); // 35
      client.println(); // 2
      
      Serial.println(F("Header sent"));
      
      int32_t time = millis();
      // Read all the data up to # bytes!
      byte wCount = 0; // For counting # of writes
      while (jpglen > 0) {
        uint8_t *buffer;
        uint8_t bytesToRead = min(32, jpglen); // change 32 to 64 for a speedup but may not work with all setups!
        buffer = cam.readPicture(bytesToRead);
        client.write(buffer, bytesToRead);
    
        if(++wCount >= 64) { // Every 2K, give a little feedback so it doesn't appear locked up
          Serial.print('.');
          wCount = 0;
        }
        //Serial.print("Read ");  Serial.print(bytesToRead, DEC); Serial.println(" bytes");
        jpglen -= bytesToRead; 
  }
  
client.println(); // 2
client.println(F("--UH3xBZZtzewr09oPP--")); // 23

This code is executed when the connection is established. This is the code on the server side:

<?php

  $estensioni_consentite = array('image/jpeg', 'image/jpg');
  $base_dir = '';
  $default_name = 'cam.jpg';
    
    if (move_uploaded_file($_FILES['picture']['tmp_name'], $base_dir.$default_name)) {
      echo "The file has been uploaded";
    }
    else {
      echo "There was an error uploading the file, please try again!";
    }  

?>

The Arduino does transmit something, I can see the answer from the answer on the terminal. On the server side, an image gets created with the right side but it is corrupted. Does anybody can help me with that ? Did I make a mistake in the code ? Thanks !

The boundary on the Content-type line should be in double quotes but I guess that doesn't make much of a difference. What gets stored on the server side? What size does the file have? Have you tried to print the whole content of the picture to the serial interface and build the difference of the two files?

Hello Marco26 Did you have much luck with this? Care to share your final code?

Any updates on this? I'm having the same problem!