Drupal\file\Plugin\rest\resource\FileUploadResource->post() has a lot of useful file handling code which can be reused. Currently it's tied to the Field API with lines such as $destination = $this->getUploadLocation($field_definition->getSettings());. This prevents its use when not using the field API (e.g. Webform).

While $field_definition->getSettings() is the most obvious, there could be others. Removing this from the post() method means it would be possible to extend the class and only need to override some helper methods, such as getUploadLocation() and validateAndLoadFieldDefinition().

Let me know if I need to provide further information or a specific use case.

Comments

imclean created an issue. See original summary.

imclean’s picture

Alternatively, the file handling code could be moved outside post().

imclean’s picture

Status: Active » Closed (duplicate)
Related issues: +#2940383: [META] Unify file upload logic of REST and JSON:API
imclean’s picture