Binary.InferContentType
BinaryInfers the MIME content type and optional encoding information from a binary stream.
Syntax
Binary.InferContentType(source as binary) as recordParameters
| Name | Type | Required | Description |
|---|---|---|---|
source | binary | Yes | The binary stream to inspect for content type inference. |
Return Value
record — A 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 aContent.Encodingfield with the encoding. - If the content type is
text/csvwith a delimited format, the record includes aCsv.PotentialDelimiterfield containing a table of potential delimiter characters for further analysis. - If the content type is
text/csvwith a fixed-width format, the record includes aCsv.PotentialPositionsfield 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
ContentTypeApplied Steps
Extracts the Content.Type field from the inferred record, yielding "text/csv".
Value | |
|---|---|
| 1 | text/csv |
Compatibility
✓ Power BI Desktop✓ Power BI Service✓ Excel Desktop✓ Excel Online✓ Dataflows✓ Fabric Notebooks