Binary.InferContentType

Binary

Infers the MIME content type and optional encoding information from a binary stream.

Examples on this page use shared sample tables. View them to understand the input data before reading the examples below.

Syntax

Binary.InferContentType(source as binary) as record

Parameters

NameTypeRequiredDescription
sourcebinaryYesThe binary stream to inspect for content type inference.

Return Value

recordA record containing Content.Type (MIME type) and optionally Content.Encoding and Csv.PotentialDelimiter or Csv.PotentialPositions.

Remarks

Binary.InferContentType inspects a binary stream and returns a record with a Content.Type field containing the inferred MIME type (e.g., "text/csv", "application/json").

Additional fields may be present depending on the inferred type:

  • If the content type is text/* and an encoding code page is detected, the record includes a Content.Encoding field with the encoding.
  • If the content type is text/csv with a delimited format, the record includes a Csv.PotentialDelimiter field containing a table of potential delimiter characters for further analysis.
  • If the content type is text/csv with a fixed-width format, the record includes a Csv.PotentialPositions field containing a list of potential column positions.

This function is useful when processing binary data from unknown sources and you need to determine the format before parsing.

Examples

Example 1: Infer the content type of a CSV-like binary

let
    CsvData = Text.ToBinary("Name,Age#(lf)Alice,30#(lf)Bob,25"),
    Inferred = Binary.InferContentType(CsvData),
    ContentType = Inferred[Content.Type]
in
    ContentType
Applied Steps

Extracts the Content.Type field from the inferred record, yielding "text/csv".

Value
1text/csv

Compatibility

Power BI Desktop Power BI Service Excel Desktop Excel Online Dataflows Fabric Notebooks