Problem with FILE_WRITE on .WAV files?

Hello Arduino community, I have a project where I need to retrieve some audio files from an online database. I have an ethernet shield (w/ micro sd card) and connectivity is fine.

Previously, I have successfully downloaded .png and .txt files from the database and stored them to the sd card with no problem. However I can’t seem to do it with .wav files. Could an expert please explain to me why I am facing this problem?

Here is the code which I am using

// Gets a file from the Internet and saves it to the SD card
// Removes the incoming HTTP header, saves the file only
// References - Arduino Example sketches from IDE by David A. Mellis et al.:
// -- File --> Examples --> Ethernet --> WebClient
// -- File --> Examples --> SD --> ReadWrite
// Author: W.A. Smith    Date: 10 June 2015

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

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // MAC address of the ethernet shield
IPAddress server(192, 168, 100, 13);    // change server to get file from here
IPAddress ip(192, 168, 100, 99);        // static ip address that I assigned to the arduino ethernet shield
EthernetClient client;

boolean currentLineIsBlank = true;
File theFile;

void setup() {
  //*************************Initialize SD Card***************************************
  // disable Ethernet chip
  pinMode(10, OUTPUT);
  digitalWrite(10, HIGH);
  Serial.print(F("Initializing SD card..."));

  if (!SD.begin(4)) {
    Serial.println(F(" initialization failed!"));
  Serial.println(F(" initialization done."));
  if (SD.exists("recording1.wav")) {
  digitalWrite(10, LOW);  
  // start the Ethernet connection:
  if (Ethernet.begin(mac) == 0) {
    Serial.println(F("Failed to configure Ethernet using DHCP"));  // no point in carrying on, so do nothing forevermore:
  // try to congifure using IP address instead of DHCP:
  // digitalWrite(10,LOW); // Do I need to enable Ethernet Chip here?
    Ethernet.begin(mac, ip);

  // give the Ethernet shield a second to initialize:

  // if you get a connection, report back via serial:
  if (client.connect(server, 80)) {
    // Make a HTTP request:
    client.println("GET /recording1.wav HTTP/1.1");  // change resource to get here , Do I need to put 'HTTP/1.1' at the end?
    client.println("Host:");    // change resource host here, Set the IP address to the server's (my computer's) IP
    client.println("Connection: close");
  else {
    // didn't get a connection to the server:
    Serial.println("connection failed");
  // open the file for writing
  Serial.println("Creating file.");
  theFile ="recording1.wav", FILE_WRITE);  // change file name to write to here
  if (!theFile) {
    Serial.println("Could not create file");
    while (1);

void loop() {
  // if there are incoming bytes available
  // from the server, read them and print them:
  if (client.available()) {
    char c =;
    if (c == '\n' && currentLineIsBlank) {
      // end of HTTP header, now save requested file
      while (client.connected()) {
        // stay in this loop until the file has been received
        if (client.available()) {
          c =;  // get file byte
          theFile.print(c);   // save file byte
    // detect the end of the incoming HTTP header
    if (c == '\n') {
      // starting a new line
      currentLineIsBlank = true;
    else if (c != '\r') {
      // got a character on the current line
      currentLineIsBlank = false;

  // if the server's disconnected, stop the client:
  if (!client.connected()) {
    Serial.println("Finished writing to file");
    // do nothing forevermore:
    while (true);

Is your I-tunes card out of money? Sorry it's not helpful, it's just the first thing that came to mind 8)

I don't have any helpful advice unfortunately.

I don't think the SD library handles long filenames, so the filename "recording1.wav" won't work. You have to use 8.3 format.


However I can't seem to do it with .wav files. Could an expert please explain to me why I am facing this problem?

Without knowing what "this problem" is? No.