> ## 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.

# Get File

> Get metadata for a specific file

<Note>
  This endpoint requires authentication.
</Note>

### Path Parameters

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

### Response

<ResponseField name="id" type="string">
  File's unique identifier (UUID)
</ResponseField>

<ResponseField name="originalName" type="string">
  Original filename
</ResponseField>

<ResponseField name="url" type="string">
  URL to access the file
</ResponseField>

<ResponseField name="key" type="string">
  Storage key/path of the file
</ResponseField>

<ResponseField name="contentType" type="string">
  MIME type of the file
</ResponseField>

<ResponseField name="size" type="integer">
  File size in bytes
</ResponseField>

<ResponseField name="provider" type="string">
  Storage provider used (s3 or local)
</ResponseField>

<ResponseField name="providerMetadata" type="object" required={false}>
  Provider-specific metadata
</ResponseField>

<ResponseField name="uploadedBy" type="string">
  UUID of the user who uploaded the file
</ResponseField>

<ResponseField name="createdAt" type="string">
  Upload timestamp in ISO 8601 format
</ResponseField>

<ResponseField name="updatedAt" type="string">
  Last update timestamp in ISO 8601 format
</ResponseField>

### 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
  * 404 Not Found: File not found
</Note>

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

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

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

    return response.json();
  };

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

  ```swift Swift theme={null}
  func getFile(accessToken: String, id: UUID) async throws -> File {
      var urlRequest = URLRequest(url: URL(string: "https://api.tktchurch.com/v1/files/\(id)")!)
      urlRequest.setValue("Bearer \(accessToken)", forHTTPHeaderField: "Authorization")
      
      let (data, 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 != 200 {
          throw URLError(.badServerResponse)
      }
      
      return try JSONDecoder().decode(File.self, from: data)
  }

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

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

      return 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}")
                  }
              }
              
              val body = response.body?.string() ?: throw IOException("Empty response")
              Json.decodeFromString<File>(body)
          }
      }
  }

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

  ```typescript React Native theme={null}
  const getFile = async (accessToken: string, id: string): Promise<File> => {
    try {
      const response = await axios.get<File>(
        `https://api.tktchurch.com/v1/files/${id}`,
        {
          headers: {
            'Authorization': `Bearer ${accessToken}`
          },
        }
      );
      return response.data;
    } 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 get file');
      }
      throw error;
    }
  };

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

<ResponseExample>
  ```json 200 Success theme={null}
  {
    "id": "123e4567-e89b-12d3-a456-426614174000",
    "originalName": "example.jpg",
    "url": "https://storage.example.com/uploads/abc123.jpg",
    "key": "uploads/abc123.jpg",
    "contentType": "image/jpeg",
    "size": 1048576,
    "provider": "s3",
    "providerMetadata": {
      "bucket": "my-bucket",
      "region": "us-east-1"
    },
    "uploadedBy": "123e4567-e89b-12d3-a456-426614174001",
    "createdAt": "2024-01-20T15:00:00Z",
    "updatedAt": "2024-01-20T15:00:00Z"
  }
  ```

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

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