FileUploadHandler
class FileUploadHandler (View source)
Handles validating and creating file entities from file uploads.
Constants
| DEFAULT_EXTENSIONS |
The default extensions if none are provided. |
Properties
| protected FileSystemInterface | $fileSystem | The file system service. |
|
| protected EntityTypeManagerInterface | $entityTypeManager | The entity type manager. |
|
| protected StreamWrapperManagerInterface | $streamWrapperManager | The stream wrapper manager. |
|
| protected EventDispatcherInterface | $eventDispatcher | The event dispatcher. |
|
| protected AccountInterface | $currentUser | The current user. |
|
| protected MimeTypeGuesserInterface | $mimeTypeGuesser | The MIME type guesser. |
|
| protected RequestStack | $requestStack | The request stack. |
Methods
Constructs a FileUploadHandler object.
Creates a file from an upload.
Move the uploaded file from the temporary path to the destination.
Gets the list of allowed extensions and updates the validators.
Loads the first File entity found with the specified URI.
Details
__construct(FileSystemInterface $fileSystem, EntityTypeManagerInterface $entityTypeManager, StreamWrapperManagerInterface $streamWrapperManager, EventDispatcherInterface $eventDispatcher, MimeTypeGuesserInterface $mimeTypeGuesser, AccountInterface $currentUser, RequestStack $requestStack)
Constructs a FileUploadHandler object.
FileUploadResult
handleFileUpload(UploadedFileInterface $uploadedFile, array $validators = [], string $destination = 'temporary://', int $replace = FileSystemInterface::EXISTS_REPLACE)
Creates a file from an upload.
protected bool
moveUploadedFile(UploadedFileInterface $uploadedFile, string $uri)
Move the uploaded file from the temporary path to the destination.
protected string
handleExtensionValidation(array $validators)
Gets the list of allowed extensions and updates the validators.
This will add an extension validator to the list of validators if one is not set.
If the extension validator is set, but no extensions are specified, it means all extensions are allowed, so the validator is removed from the list of validators.
protected FileInterface|null
loadByUri(string $uri)
Loads the first File entity found with the specified URI.