Drupal is a registered trademark of Dries Buytaert
drupal 11.3.7 Update released for Drupal core (11.3.7)! drupal 11.2.11 Update released for Drupal core (11.2.11)! drupal 10.6.7 Update released for Drupal core (10.6.7)! drupal 10.5.9 Update released for Drupal core (10.5.9)! cms 2.1.1 Update released for Drupal core (2.1.1)! drupal 11.3.6 Update released for Drupal core (11.3.6)! drupal 10.6.6 Update released for Drupal core (10.6.6)! cms 2.1.0 Update released for Drupal core (2.1.0)! bootstrap 8.x-3.40 Minor update available for theme bootstrap (8.x-3.40). menu_link_attributes 8.x-1.7 Minor update available for module menu_link_attributes (8.x-1.7). eca 3.1.1 Minor update available for module eca (3.1.1). layout_paragraphs 2.1.3 Minor update available for module layout_paragraphs (2.1.3). ai 1.3.3 Minor update available for module ai (1.3.3). ai 1.2.14 Minor update available for module ai (1.2.14). node_revision_delete 2.0.3 Minor update available for module node_revision_delete (2.0.3). moderated_content_bulk_publish 2.0.52 Minor update available for module moderated_content_bulk_publish (2.0.52). klaro 3.0.10 Minor update available for module klaro (3.0.10). klaro 3.0.9 Minor update available for module klaro (3.0.9). layout_paragraphs 2.1.2 Minor update available for module layout_paragraphs (2.1.2). geofield_map 11.1.8 Minor update available for module geofield_map (11.1.8).

About

Enable file upload mutations for GraphQL using the Multipart HTTP Request. Based on module graphql_compose.

Features

  • Upload files via GraphQL mutations
  • Validates file uploads against field instance settings
  • Supports any file field on any entity type
  • Returns proper error violations for invalid uploads
  • Based on the GraphQL Compose schema

Requirements

Usage

GraphQL Mutation

The module adds a fileUpload mutation to the GraphQL schema:

mutation UploadFile($file: Upload!, $metadata: fieldMetadata!) {
  fileUpload(file: $file, metadata: $metadata) {
    errors {
      message
    }
    results {
      entity {
        ... on File {
          id
          url
          filename
        }
      }
    }
  }
}

Metadata Input

The fieldMetadata input requires:

Field Type Description field_name String! The machine name of the file field entity_type EntityType! The entity type (node, user, etc.) entity_bundle String! The bundle of the entity

Example: Upload a File

JS example

const operation = {
  query: `
    mutation UploadFile($file: Upload!, $metadata: fieldMetadata!) {
      fileUpload(file: $file, metadata: $metadata) {
        errors {
          message
        }
        results {
          entity {
            ... on File {
              id
              url
              filename
              mimetype
              filesize
            }
          }
        }
      }
    }
  `,
  variables: {
    file: null, // Set by FormData
    metadata: {
      field_name: 'field_document',
      entity_type: 'node',
      entity_bundle: 'article',
    },
  },
};

const formData = new FormData();
formData.append('operations', JSON.stringify(operation));
formData.append('map', JSON.stringify({ 0: ['variables.file'] }));
formData.append(0, fileUpload);

fetch('https://example.com/graphql', {
  method: 'POST',
  body: formData,
});

curl example

# Create file
curl https://example.com/graphql \
  -F operations='{  "query": "fileUploadMutation ($file: Upload!) { fileUpload( file: $file, metadata: { field_name: \"field_my_file\", entity_type: NODE, entity_bundle: \"event\" } ) { errors results { entity_bundle entity_type id values } }}", "variables": { "file": null }}' \
  -F map='{ "0": ["variables.file"] }' \
  -F 0=@/path/to/myfile.pdf

# Create image
curl https://example.com/graphql \
  -F operations='{  "query": "mutation ($file: Upload!) { fileUpload( file: $file, metadata: { field_name: \"field_my_file\", entity_type: NODE, entity_bundle: \"event\" } ) { errors results { entity_bundle entity_type id values } }}", "variables": { "file": null }}' \
  -F map='{ "0": ["variables.file"] }' \
  -F 0=@/path/to/myimage.jpeg

Response Type

The mutation returns an AnyFileUploadResponse with:

Field Type Description errors [Violation] Array of validation violations (if any) results AnyEntity The uploaded file entity

Security

  • File uploads are validated against Drupal's field instance settings
  • File size restrictions are enforced
  • Allowed file extensions are validated
  • Access control respects Drupal's permissions

Troubleshooting

Upload returns validation errors

Check that:

  1. The field exists on the specified entity bundle
  2. The file extension is allowed by the field settings
  3. The file size is within limits
  4. The user has permission to create files

File is not saved

Ensure:

  1. The file system is writable
  2. The upload directory exists and is configured
  3. PHP's upload_max_filesize and post_max_size are sufficient

Activity

Total releases
3
First release
Jan 2026
Latest release
2 months ago
Release cadence
0 days
Stability
33% stable

Release Timeline

Releases

Version Type Release date
2.0.1 Stable Jan 23, 2026
2.0.x-dev Dev Jan 23, 2026
1.0.x-dev Dev Jan 23, 2026