How large a file can the Web server/SD example serve up?

Have had no problems getting text files to serve up to my other machines but anything larger (eg an mp3) will only transfer over as a zero-ish byte file despite the file size showing up correctly on the page. Using the last example at http://www.ladyada.net/learn/arduino/ethfiles.html

Could it be because it's a binary file, rather than the size that is causing the problem? What happens if you create a text file of similar size - any problems with that?

Can't believe I didn't consider that. Getting closer now at least. I am basically trying to get an mp4 file on the sd card to stream to the browser or VLC on my PC. Changing content-type to video/mp4 at least tries to start it transferring now but again i just get a zero byte file in the end. Hmm.

Are you loading the entire file before serving it ? You might be running out of ram...

I am basically using a minimally modified version of that example. I had assumed the target PC would just read the file from the sd card over the network and play/decode/download it from there.

int16_t c;
          while ((c = file.read()) > 0) {
              // uncomment the serial to debug (slow!)
              //Serial.print((char)c);
              client.print((char)c);
          }

looks like the file is sent through the network one byte at a time, so my concern doesn't apply.

Below is some SD file test code. It serves the 253222 byte HYPNO.JPG, slow, but complete.

//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);
  digitalWrite(10,HIGH);

  //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) {
            //Serial.println("test.txt:");
            // read from the file until there's nothing else in it:
            while (myFile.available()) {
              client.write(myFile.read());
            }
            // close the file:
            myFile.close();

          }
            delay(1);
            //stopping client
            client.stop();
            readString="";
          //}
        }
      }
    }
  } 
}

I had assumed the target PC would just read the file from the sd card over the network and play/decode/download it from there.

No. The SD card is not connected to the network, so it can't be read "over the network". Only the Ethernet shield is connected to the network. While the SD card may be on the ethernet shield, and while it may also use SPI to communicate with the Arduino, the Ethernet chip has no idea that there is a SD card over there. Only the Arduino knows. So, it must get the requested data from where it knows that it lives, and send it out.

Stalkid64: Can't believe I didn't consider that. Getting closer now at least. I am basically trying to get an mp4 file on the sd card to stream to the browser or VLC on my PC. Changing content-type to video/mp4 at least tries to start it transferring now but again i just get a zero byte file in the end. Hmm.

You would also need to specify the content encoding, and then actually encode it in the encoding scheme you specified.

There could be zero bytes in the mp4 file. OTOH, if the bytes you get are all zeros, then yes, there’s a problem :slight_smile: