Skip to content

Add Multipart File Upload Support #16

@DanielDAfework

Description

@DanielDAfework

Description

The dotnet-anvil client currently doesn't support multipart file uploads for GraphQL mutations. When users attempt to upload files using the standard base64 format (matching our Node.js client API), they receive an IOException: Unable to write data to the transport connection: Broken pipe error.

Example

A user attempts to create a cast with a PDF file:

var query = @"
        mutation createCast(
          $title: String,
          $file: Upload!,
          $isTemplate: Boolean,
          $detectFields: Boolean
        ) {
          createCast (
          title: $title,
          file: $file,
          isTemplate: $isTemplate,
          detectFields: $detectFields
          ) {
          eid
          name
          title
          isTemplate
          }
        }
      ";

var variables = new {
    title = "Testing from the code",
    file = new {
        data = "Base64 encoded file...",
        mimetype = "application/pdf", 
        filename = "test-code"
    },
    isTemplate = true
};
var response = await client.SendQuery(query, variables);

The client sends this as JSON with embedded base64 data, but Anvil's GraphQL endpoint expects multipart/form-data format for file uploads per the GraphQL multipart request spec.

Proposed Solution

Update the SendQuery method in the dotnet-anvil client to:

  1. Detect when mutations contain Upload type parameters
  2. Transform base64 file objects to FileStreamVariable instances (required by GraphQL.Client library)
  3. Let GraphQL.Client handle the multipart/form-data formatting.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions