 
     if ( !request->hasArg( "filename" ) )
     {
+      xSemaphoreGive( x_SPI_Mutex );
       return request->send( 400, textPlainHeader, "Invalid filename." );
     }
 

    }
  });

  server.on( "/api/upload", HTTP_POST,
  []( AsyncWebServerRequest * request )
  {
    request->send( 200 );
  },
  []( AsyncWebServerRequest * request, String filename, size_t index, uint8_t *data, size_t len, bool final )
  {
    if ( xSemaphoreTake( x_SPI_Mutex, SPI_MutexMaxWaitTime ) )
    {
      static File   newFile;
      static bool   _authenticated;
      static time_t startTimer;

      if ( !index )
      {
        _authenticated = false;
        if ( request->authenticate( www_username, www_password ) )
        {
          startTimer = millis();
          Serial.printf( "Starting upload. filename = %s\n", filename.c_str() );
          if ( !filename.startsWith( "/" ) )
          {
            filename = "/" + filename;
          }
          if ( filename == defaultTimerFile )
          {
            newFile = SPIFFS.open( filename, "w" );
          }
          else
          {
            newFile = SD.open( filename, "w" );
          }
          _authenticated = true;
        }
        else
        {
          Serial.println( "Unauthorized access." );
          request->send( 401, "text/plain", "Not logged in." );
        }
      }

      if ( _authenticated )
      {
        newFile.write( data, len );
      }

      if ( _authenticated && final )
      {
        newFile.close();
        if ( filename == defaultTimerFile )
        {
          defaultTimersLoaded();
        }
        Serial.printf( "Upload %iBytes in %.2fs which is %.2ikB/s.\n", index, ( millis() - startTimer ) / 1000.0, index / ( millis() - startTimer ) );
      }
      xSemaphoreGive( x_SPI_Mutex );
    }
    else
    {
      request->send( 503, textPlainHeader, "SPI bus not available." );
    }
  });

  // / or 'index.htm'


    else if ( request->hasArg( "tftorientation" ) )
    {
      if ( !xSemaphoreTake( x_SPI_Mutex, SPI_MutexMaxWaitTime ) )
      {
        return request->send( 501, textPlainHeader, "SPI bus not available" );
      }

      if (  request->arg( "tftorientation" ) == "normal" )
      {
        tftOrientation = TFT_ORIENTATION_NORMAL;
