All Products
Search
Document Center

Realtime Compute for Apache Flink:FETCH_CONTENT

Last Updated:Jun 02, 2026

Downloads a file from a URI and returns its content as a byte array.

Engine requirement

The FETCH_CONTENT function requires Ververica Runtime (VVR) 11.6.0 or later.

Syntax

VARBINARY FETCH_CONTENT(VARCHAR uri)
VARBINARY FETCH_CONTENT(VARCHAR uri, INTEGER httpRetryCount)

Parameters

Parameter

Type

Description

uri

VARCHAR

The file URI. Supported schemes include HTTP, HTTPS, and any scheme supported by the Flink FileSystem:

  • http:// or https://: An HTTP or HTTPS link.

  • oss://: An Alibaba Cloud OSS path.

  • hdfs://: An HDFS path.

  • file://: A local file path.

httpRetryCount

INTEGER

Optional. Number of retries for HTTP/HTTPS requests. Default: 3. Throws an exception after all httpRetryCount retries fail.

Note
  • Returns NULL if uri is NULL. For a non-NULL uri, a failed download throws an exception.

  • If the uri specifies an OSS path, configure access credentials as described in Configure bucket authentication.

  • If httpRetryCount is negative or NULL, the default value is used.

Return value

Type

Description

VARBINARY

File content

Example 1

  • Test data

    Table 1. T1

    input

    uri (VARCHAR)

    1

    http://example.com/image_url

    2

    oss://example-bucket/example.pdf

    3

    NULL

  • Test query

    SELECT 
        id,
        FETCH_CONTENT(uri) AS `value`
    FROM 
        T1;
  • Test result

    id (INT)

    value (VARBINARY)

    1

    x'ffd8ffe00010......'

    2

    x'aaffd8ffe000......'

    3

    NULL

Example 2

  • Test data

    Table 1. T2

    id (INT)

    uri (VARCHAR)

    1

    http://example.com/image_url

    2

    http://example.com/not_exist_image_url

  • Test query

    SELECT 
        id,
        FETCH_CONTENT(uri, 5) AS `value`
    FROM 
        T2;
  • Test result

    id (INT)

    value (VARBINARY)

    1

    x'ffd8ffe00010......'

    If the URL does not exist, the function throws an exception after 5 retries:

    Caused by: java.io.IOException: HTTP request failed with response code: 404 for URL

References