function TemporaryJsonapiFileFieldUploader::streamUploadData

Same name in other branches
  1. 9 core/modules/jsonapi/src/Controller/TemporaryJsonapiFileFieldUploader.php \Drupal\jsonapi\Controller\TemporaryJsonapiFileFieldUploader::streamUploadData()
  2. 8.9.x core/modules/jsonapi/src/Controller/TemporaryJsonapiFileFieldUploader.php \Drupal\jsonapi\Controller\TemporaryJsonapiFileFieldUploader::streamUploadData()
  3. 10 core/modules/jsonapi/src/Controller/TemporaryJsonapiFileFieldUploader.php \Drupal\jsonapi\Controller\TemporaryJsonapiFileFieldUploader::streamUploadData()

Streams file upload data to temporary file and moves to file destination.

Return value

string The temp file path.

Throws

\Symfony\Component\HttpKernel\Exception\HttpException Thrown when input data cannot be read, the temporary file cannot be opened, or the temporary file cannot be written.

1 call to TemporaryJsonapiFileFieldUploader::streamUploadData()
TemporaryJsonapiFileFieldUploader::handleFileUploadForField in core/modules/jsonapi/src/Controller/TemporaryJsonapiFileFieldUploader.php
Creates and validates a file entity for a file field from a file stream.

File

core/modules/jsonapi/src/Controller/TemporaryJsonapiFileFieldUploader.php, line 352

Class

TemporaryJsonapiFileFieldUploader
Reads data from an upload stream and creates a corresponding file entity.

Namespace

Drupal\jsonapi\Controller

Code

protected function streamUploadData() {
    // Catch and throw the exceptions that JSON API module expects.
    try {
        $temp_file_path = $this->inputStreamFileWriter
            ->writeStreamToFile();
    } catch (UploadException $e) {
        $this->logger
            ->error('Input data could not be read');
        throw new HttpException(500, 'Input file data could not be read', $e);
    } catch (CannotWriteFileException $e) {
        $this->logger
            ->error('Temporary file data for could not be written');
        throw new HttpException(500, 'Temporary file data could not be written', $e);
    } catch (NoFileException $e) {
        $this->logger
            ->error('Temporary file could not be opened for file upload');
        throw new HttpException(500, 'Temporary file could not be opened', $e);
    }
    return $temp_file_path;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.