Skip to content

[Bug] SharePointService.CreateFile() only work with text value file content #306

@emibanana

Description

@emibanana

Describe the bug

SharePointService.CreateFile via the @microsoft/power-apps SDK saves corrupted or non-binary file content to SharePoint when uploading images. The file is not openable by any image viewer.

Steps to Reproduce

try upload a photos using CreateFile(dataset: string, folderPath: string, name: string, body: string, queryParametersSingleEncoded?: boolean) where no matter what passed into the body parameters it will always end up corrupted, becoming pure text value

Expected behavior

A valid binary image file (JPEG/PNG) is saved to the target SharePoint document library folder and is openable by any image viewer.

Actual behavior

The uploaded file contains corrupted content. Three variations were observed depending on how the body parameter was prepared:

Body passed to CreateFile File content saved to SharePoint
JSON.stringify({ $content-type, $content }) "{\"$content-type\":\"image/png\",\"$content\":\"iVB...\"}" — double-serialised JSON string including outer quotes
Plain object { $content-type, $content } {"$content-type":"image/png","$content":"iVB..."} — JSON envelope object stored as text
Raw base64 string "iVBORw0KGgo..." — base64 ASCII text stored instead of binary bytes

In all cases the connector operation CreateFile stores text in the file rather than decoding to binary bytes.

Screenshots or Error Messages

you wont need a screenshot to understand this

Environment information

  • Framework / build tool: React 19, Vite 7, TypeScript (strict)
  • SDK: @microsoft/power-apps (Power Apps Code App)
  • Connection: SharePoint Online connector (shared_sharepointonline)
  • Operation: SharePointService.CreateFile(dataset, folderPath, name, body)
  • Schema: body is declared "in": "body", "format": "binary", "type": "string" in the connector OpenAPI schema

Additional context

Root cause traced through SDK source:

  1. ConnectorDataOperationExecutor._buildOperationBodyParam calls JSON.stringify(params[bodyParam.name]) on the body value regardless of the parameter's format field
  2. The result is passed to retrieveDataAsync, which wraps it in new Blob([body], { type: 'application/json' }) and sends to the Power Platform gateway
  3. The gateway forwards the JSON-encoded string body to the SharePoint REST API endpoint (POST /{connectionId}/datasets/{dataset}/files)
  4. SharePoint stores the received text payload verbatim instead of binary image bytes

The SDK does not special-case format: binary body parameters in connector operations — it always JSON-serialises them. A native binary/octet-stream passthrough path (uploadDataAsync) exists in runtimeDataClient but is only wired up for Dataverse file column uploads, not connector operations.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Fix rolling outWe start the rollout with the fix for this issue.Known IssueThis is a known issue.bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions