This service handles file uploads.
Due to specific
EntityObject class operation, "File" custom fields are stored as integers (int).
Accordingly, when writing a value into element object, the file must be already saved in the database.
During this process, a situation is possible, when the file was saved, but the element was not. In this case, you must delete this "handling" file.
This service is responsible for such operations.
Service instance must be retrieved from container.
Upon creating an object, the service registers the function (via
register_shutdown_function), which will be executed when finalizing
php-process. This function will delete all unsaved files.
Life cycle looks as follows:
- File data to be saved for the element. File is stored via the method
- When saving the element, calls the method
- When element wasn't saved, files unmarked as saved, will be deleted.
This life cycle operates in REST and method
|Method||Description||Available from version|
public function saveFileTemporary(Field $field, array $fileData): ?int
|Saves $fileData file data for $field. On success returns the new file ID.|
public function markFileAsPersistent(int $fileId): self
|Marks file with $fileId as saved (shall not be deleted).|
public function deleteTemporaryFiles(): self
|Deletes all temporary files.|
public function saveFilePersistently(Field $field, array $fileData): ?int
|Saves file on a recurring basis. Arguments are similar to the method |