Skip to main content

Get File

Description

The get_file function retrieves a file from the web service based on a provided file ID. It returns a WebServiceResult containing the response from the web service.

Function Signature:

def get_file(ws_config: WebServiceConfig, file_id: int) -> WebServiceResult:

Parameters

  • ws_config (WebServiceConfig): Configuration object for the web service.
  • file_id (int): The ID of the file to be retrieved.

Returns

  • WebServiceResult: The result of the web service request, which includes:
    • http_response_code: The HTTP response code from the server (e.g., 200 for success).
    • http_response_string: The response body from the server, which may contain file information or errors.
    • json_data: The parsed JSON response data, if available.

Example Usage

ws_config = WebServiceConfig(base_url="https://api.actionstreamer.com")
file_id = 12345

result = get_file(ws_config, file_id)
print(result.http_response_code, result.http_response_string)

Behavior

  • Sends a GET request to the server to retrieve the file details using the provided file ID.
  • If the request is successful (HTTP 200), the response will contain the file's metadata in JSON format.
  • Returns a WebServiceResult containing the response code, message, and parsed JSON data.

Error Handling

  • General Exception: If any exception occurs during the request or processing, the function logs the error, sets the response code to -1, and includes a message in the response string indicating the failure.