TemporaryJsonapiFileFieldUploader
class TemporaryJsonapiFileFieldUploader (View source)
| internal | This will be removed once https://www.drupal.org/project/drupal/issues/2940383 lands. |
Reads data from an upload stream and creates a corresponding file entity.
This is implemented at the field level for the following reasons:
- Validation for uploaded files is tied to fields (allowed extensions, max size, etc..).
- The actual files do not need to be stored in another temporary location, to be later moved when they are referenced from a file field.
- Permission to upload a file can be determined by a user's field- and entity-level access.
Constants
| REQUEST_HEADER_FILENAME_REGEX |
The regex used to extract the filename from the content disposition header. |
| BYTES_TO_READ |
The amount of bytes to read in each iteration when streaming file data. |
Properties
| protected LoggerInterface | $logger | A logger instance. |
|
| protected FileSystemInterface | $fileSystem | The file system service. |
|
| protected MimeTypeGuesserInterface | $mimeTypeGuesser | The MIME type guesser. |
|
| protected Token | $token | The token replacement instance. |
|
| protected LockBackendInterface | $lock | The lock service. |
|
| protected ImmutableConfig | $systemFileConfig | System file configuration. |
|
| protected EventDispatcherInterface | $eventDispatcher | The event dispatcher. |
Methods
Constructs a FileUploadResource instance.
Creates and validates a file entity for a file field from a file stream.
Validates and extracts the filename from the Content-Disposition header.
Checks if the current user has access to upload the file.
Streams file upload data to temporary file and moves to file destination.
Prepares the filename to strip out any malicious extensions.
Determines the URI for a file field.
Retrieves the upload validators for a field definition.
Generates a lock ID based on the file URI.
Details
__construct(LoggerInterface $logger, FileSystemInterface $file_system, MimeTypeGuesserInterface $mime_type_guesser, Token $token, LockBackendInterface $lock, ConfigFactoryInterface $config_factory, EventDispatcherInterface $event_dispatcher = NULL)
Constructs a FileUploadResource instance.
FileInterface|EntityConstraintViolationListInterface
handleFileUploadForField(FieldDefinitionInterface $field_definition, string $filename, AccountInterface $owner)
Creates and validates a file entity for a file field from a file stream.
string
validateAndParseContentDispositionHeader(Request $request)
Validates and extracts the filename from the Content-Disposition header.
static AccessResultInterface
checkFileUploadAccess(AccountInterface $account, FieldDefinitionInterface $field_definition, EntityInterface $entity = NULL)
Checks if the current user has access to upload the file.
protected string
streamUploadData()
Streams file upload data to temporary file and moves to file destination.
protected EntityConstraintViolationListInterface
validate(FileInterface $file, array $validators)
Validates the file.
protected string
prepareFilename(string $filename, array $validators)
Prepares the filename to strip out any malicious extensions.
protected string
getUploadLocation(array $settings)
Determines the URI for a file field.
protected array
getUploadValidators(FieldDefinitionInterface $field_definition)
Retrieves the upload validators for a field definition.
This is copied from \Drupal\file\Plugin\Field\FieldType\FileItem as there is no entity instance available here that a FileItem would exist for.
static protected string
generateLockIdFromFileUri(string $file_uri)
Generates a lock ID based on the file URI.