Documentation

FileUploader

General


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:

  1. File data to be saved for the element. File is stored via the method saveFileTemporary.
  2. When saving the element, calls the method markFileAsPersistent.
  3. When element wasn't saved, files unmarked as saved, will be deleted.

This life cycle operates in REST and method Item::setFromCompatibleData.

Methods


© «Bitrix24», 2001-2024
Method Description Available from version
public function saveFileTemporary(Field $field, array $fileData): ?int

  • $field - field object. This must be a "File" custom field.
  • $fileData - file data; structure is similar to the array with description of uploaded file (see \CFile::MakeFileArray()).
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 saveFileTemporary.