Uploading image from Arduino to Mysql Database

Hi, I've search the forum and took some time reading some threads but could not get the exact scenario of my problem. Im quite new to arduino and in our project im trying to send an image that is stored from the SD card attached in the wifi shield and will upload in to the Mysql database via the Wireless network. All I saw was Arduino SD card as the server and some using Ethernet Shield. I'd like to seek help if there is some sample codes that uses Wifi Shield(CC3000) and uploading it to the server.

Hi, I've search the forum and took some time reading some threads but could not get the exact scenario of my problem.

Because sending an image file is exactly the same as sending a text file. The differences between the streams of data matter only to the receiver.

Your problem breaks down into three parts - getting the stream of data from the file, sending the stream of data from the Arduino to the server using the WiFi shield, and consuming the stream of data on the server.

Which parts are you having problems with?

PaulS:
Because sending an image file is exactly the same as sending a text file. The differences between the streams of data matter only to the receiver.

Your problem breaks down into three parts - getting the stream of data from the file, sending the stream of data from the Arduino to the server using the WiFi shield, and consuming the stream of data on the server.

Which parts are you having problems with?

My problem is the first two, getting the stream of data from the file and sending the stream of data from the arduino to the server using the WiFi shield. I have found some solution on receiving the data on the server end.

My problem is the first two, getting the stream of data from the file

There are examples that come with the SD library that show you how to read a file.

and sending the stream of data from the arduino to the server using the WiFi shield.

This is the non-trivial part of the project, where YOU have to do some work. Once you are connected to the server, and have sent the necessary header records, sending the data is a client.write() call, with the (buffer of) data read from the file, one block of data at a time.

macoy-marc:
I have found some solution on receiving the data on the server end.

Do you mind sharing?

Basic code for use with an ethernet shield. You will need to work out the wifi shield part.

//zoomkat 12/26/12
//SD server test code
//open serial monitor to see what the arduino receives
//address will look like http://192.168.1.102:84 when submited
//for use with W5100 based ethernet shields

#include <SD.h>
#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 
  192, 168, 1, 102 }; // ip in lan
byte gateway[] = { 
  192, 168, 1, 1 }; // internet access via router
byte subnet[] = { 
  255, 255, 255, 0 }; //subnet mask
EthernetServer server(84); //server port
String readString; 

//////////////////////

void setup(){

  Serial.begin(9600);

  // disable w5100 while setting up SD
  pinMode(10,OUTPUT);
  digitalWrite(10,HIGH);
  Serial.print("Starting SD..");
  if(!SD.begin(4)) Serial.println("failed");
  else Serial.println("ok");

  Ethernet.begin(mac, ip, gateway, gateway, subnet);
  //delay(2000);
  server.begin();
  Serial.println("Ready");
}

void loop(){
  // Create a client connection
  EthernetClient client = server.available();
  if (client) {
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();

        //read char by char HTTP request
        if (readString.length() < 100) {
          //store characters to string 
          readString += c; 
          //Serial.print(c);
        } 
        //if HTTP request has ended
        if (c == '\n') {

          ///////////////
          Serial.println(readString); //print to serial monitor for debuging 

            client.println("HTTP/1.1 200 OK"); //send new page
          //client.println("Content-Type: text/html");
          client.println("Content-Type: image/jpeg");
          //client.println("Content-Type: image/gif");
          //client.println("Content-Type: application/x-javascript");
          //client.println("Content-Type: text");

          client.println();

          //File myFile = SD.open("boom.htm");
          File myFile = SD.open("HYPNO.JPG");
          //File myFile = SD.open("BLUEH_SL.GIF");
          //File myFile = SD.open("SERVOSLD.HTM");

          if (myFile) {

            byte clientBuf[64];
            int clientCount = 0;

            while(myFile.available())
            {
              clientBuf[clientCount] = myFile.read();
              clientCount++;

              if(clientCount > 63)
              {
                // Serial.println("Packet");
                client.write(clientBuf,64);
                clientCount = 0;
              }
            }
            //final <64 byte cleanup packet
            if(clientCount > 0) client.write(clientBuf,clientCount);            
            // close the file:
            myFile.close();
          }
          delay(1);
          //stopping client
          client.stop();
          readString="";
        }
      }
    }
  } 
}

regarding this one I have found one post on this forum where you can send and image to a PC via Multi Part.
refer to this thread: http://forum.arduino.cc/index.php?topic=113470.0

and I can also receive in on the server side by a php script that stores it to a temporary folder.

Can someone help me construct the while loop and the remaining things to do when reading the image from the SD card and sending it chunk by chunk on the PC side(correct me if I’m wrong).

this is the code by the way:

uint32_t len = size_of_pict + 177; // 177 is the content without the image data
client.println(F("POST /path/to/script.php HTTP/1.0"));
client.println(F("Host: example.com"));
client.println(F("Content-type: multipart/form-data, boundary=UH3xBZZtzewr09oPP"));
client.print(F("Content-Length: "));
client.println(len);
client.println();
client.println(F("--UH3xBZZtzewr09oPP"));
client.println(F("content-disposition: form-data; name=\"picture\"; filename=\"cam.jpg\""));
client.println(F("Content-Type: image/jpeg"));
client.println(F("Content-Transfer-Encoding: binary"));
client.println();
while (has_more_pict_data) {
  client.write(pict_chunk, size_of_pict_chunk);
}
client.println();
client.println(F("--UH3xBZZtzewr09oPP--"));

sterretje:
Do you mind sharing?

and this is the PHP script that could catch the sent image and store it to a temporary folder.

<?php
 $target_dir = "../uploaded/";
 $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
 move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file); 
 echo("Done");
?>