[META] Unify file upload logic of REST and JSON:API

Created on 29 January 2018, almost 7 years ago
Updated 18 June 2024, 5 months ago

Problem/Motivation

Currently, the REST module's @RestResource=file_upload plugin contains lots of logic that was very carefully developed and tested in #1927648: Allow creation of file entities from binary data via REST requests β†’ . That issue was a monumental effort.

We don't want the JSON:API (contrib, soon core) and GraphQL modules to A) duplicate the logic since that is too risky, B) duplicate the effort. We want them to use the same hardened, proven logic.

Proposed resolution

  1. Introduce a FileFieldUploader service that extracts the file file upload logic, minus the rest.module-specific bits.
  2. Refactor the REST module's @RestResource=file_upload plugin to use this service. None of its behaviors change.
  3. Prove this by having a patch that passes tests while modifying zero tests.
  4. Prove this by having the JSON:API module also use this (done in #8).
  5. Remove FileNameLength from Drupal\file\Validation\FileValidatorSettingsTrait.php as all code paths now use the file upload handler which already adds that constraint. See this conversation for more detail.

The affected classes & code will be:

  • \Drupal\jsonapi\Controller\TemporaryJsonapiFileFieldUploader
  • \Drupal\file\Plugin\rest\resource\FileUploadResource
  • _file_save_upload_single()

Remaining tasks

This is being done in two sub-tasks:

address feedback in:

User interface changes

None.

API changes

None.

Data model changes

None.

πŸ“Œ Task
Status

Fixed

Version

11.0 πŸ”₯

Component
File moduleΒ  β†’

Last updated 9 days ago

Created by

πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024