function FileUploadResource::streamUploadData

Same name 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.

Deprecated

in drupal:10.3.0 and is removed from drupal:11.0.0. There is no replacement.

See also

https://www.drupal.org/node/3402032

File

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

Class

FileUploadResource
File upload resource.

Namespace

Drupal\file\Plugin\rest\resource

Code

protected function streamUploadData() : string {
    @\trigger_error('Calling ' . __METHOD__ . '() is deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. There is no replacement. See https://www.drupal.org/node/3402032', E_USER_DEPRECATED);
    // 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.