function FileUploadResource::streamUploadData

Same name and namespace in other branches
  1. 9 core/modules/file/src/Plugin/rest/resource/FileUploadResource.php \Drupal\file\Plugin\rest\resource\FileUploadResource::streamUploadData()
  2. 8.9.x core/modules/file/src/Plugin/rest/resource/FileUploadResource.php \Drupal\file\Plugin\rest\resource\FileUploadResource::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 FileUploadResource::streamUploadData()
FileUploadResource::post in core/modules/file/src/Plugin/rest/resource/FileUploadResource.php
Creates a file from an endpoint.

File

core/modules/file/src/Plugin/rest/resource/FileUploadResource.php, line 379

Class

FileUploadResource
File upload resource.

Namespace

Drupal\file\Plugin\rest\resource

Code

protected function streamUploadData() : string {
    // Catch and throw the exceptions that REST 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.