> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tktchurch.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Delete File

> Delete a file from storage and database

<Note>
  This endpoint requires authentication and the `deleteFiles` permission.
</Note>

### Path Parameters

<ParamField path="id" type="string" required>
  The UUID of the file to delete
</ParamField>

### Response

Returns HTTP 204 (No Content) on successful deletion.

### Error Responses

<ResponseField name="error" type="object">
  Error details when the request fails

  <Expandable title="Error Object">
    <ResponseField name="status" type="integer">
      HTTP status code
    </ResponseField>

    <ResponseField name="reason" type="string">
      Error message explaining why the request failed
    </ResponseField>
  </Expandable>
</ResponseField>

<Note>
  Common error cases:

  * 401 Unauthorized: Missing or invalid access token
  * 403 Forbidden: Missing required permission
  * 404 Not Found: File not found
</Note>

<RequestExample>
  ```bash cURL theme={null}
  curl -X DELETE "https://api.tktchurch.com/v1/files/123e4567-e89b-12d3-a456-426614174000" \
    -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIs..."
  ```

  ```javascript JavaScript theme={null}
  const deleteFile = async (accessToken, id) => {
    const response = await fetch(
      `https://api.tktchurch.com/v1/files/${id}`,
      {
        method: 'DELETE',
        headers: {
          'Authorization': `Bearer ${accessToken}`
        }
      }
    );

    if (!response.ok) {
      const error = await response.json();
      throw new Error(error.reason || 'Failed to delete file');
    }

    return response.status === 204;
  };

  // Usage
  try {
    await deleteFile(
      'eyJhbGciOiJIUzI1NiIs...',
      '123e4567-e89b-12d3-a456-426614174000'
    );
    console.log('File deleted successfully');
  } catch (error) {
    console.error('Error:', error.message);
  }
  ```

  ```swift Swift theme={null}
  func deleteFile(accessToken: String, id: UUID) async throws {
      var urlRequest = URLRequest(url: URL(string: "https://api.tktchurch.com/v1/files/\(id)")!)
      urlRequest.httpMethod = "DELETE"
      urlRequest.setValue("Bearer \(accessToken)", forHTTPHeaderField: "Authorization")
      
      let (_, response) = try await URLSession.shared.data(for: urlRequest)
      
      guard let httpResponse = response as? HTTPURLResponse else {
          throw URLError(.badServerResponse)
      }
      
      if httpResponse.statusCode == 404 {
          throw URLError(.resourceNotFound)
      }
      
      if httpResponse.statusCode != 204 {
          throw URLError(.badServerResponse)
      }
  }

  // Usage
  do {
      try await deleteFile(
          accessToken: "eyJhbGciOiJIUzI1NiIs...",
          id: UUID(uuidString: "123e4567-e89b-12d3-a456-426614174000")!
      )
      print("File deleted successfully")
  } catch {
      print("Error:", error)
  }
  ```

  ```kotlin Kotlin theme={null}
  suspend fun deleteFile(accessToken: String, id: UUID) {
      val request = Request.Builder()
          .url("https://api.tktchurch.com/v1/files/$id")
          .delete()
          .header("Authorization", "Bearer $accessToken")
          .build()

      withContext(Dispatchers.IO) {
          client.newCall(request).execute().use { response ->
              if (!response.isSuccessful) {
                  throw when (response.code) {
                      404 -> NoSuchElementException("File not found")
                      else -> IOException("Unexpected response ${response.code}")
                  }
              }
          }
      }
  }

  // Usage
  try {
      deleteFile(
          "eyJhbGciOiJIUzI1NiIs...",
          UUID.fromString("123e4567-e89b-12d3-a456-426614174000")
      )
      println("File deleted successfully")
  } catch (e: Exception) {
      println("Error: ${e.message}")
  }
  ```

  ```typescript React Native theme={null}
  const deleteFile = async (accessToken: string, id: string): Promise<void> => {
    try {
      await axios.delete(
        `https://api.tktchurch.com/v1/files/${id}`,
        {
          headers: {
            'Authorization': `Bearer ${accessToken}`
          },
        }
      );
    } catch (error) {
      if (axios.isAxiosError(error)) {
        if (error.response?.status === 404) {
          throw new Error('File not found');
        }
        throw new Error(error.response?.data?.reason || 'Failed to delete file');
      }
      throw error;
    }
  };

  // Usage
  try {
    await deleteFile(
      'eyJhbGciOiJIUzI1NiIs...',
      '123e4567-e89b-12d3-a456-426614174000'
    );
    console.log('File deleted successfully');
  } catch (error) {
    console.error('Error:', error.message);
  }
  ```
</RequestExample>

<ResponseExample>
  ```json 204 No Content theme={null}
  ```

  ```json 401 Unauthorized theme={null}
  {
    "error": {
      "status": 401,
      "reason": "Invalid or expired access token"
    }
  }
  ```

  ```json 403 Forbidden theme={null}
  {
    "error": {
      "status": 403,
      "reason": "Missing required permission: deleteFiles"
    }
  }
  ```

  ```json 404 Not Found theme={null}
  {
    "error": {
      "status": 404,
      "reason": "File not found"
    }
  }
  ```
</ResponseExample>
