$prepared_filename =
$this->
prepareFilename($filename,
$validators);
// Create the file.
$file_uri = "{
$destination}/{
$prepared_filename}";
// Using the UploadedFile method instead of streamUploadData.
$temp_file_path =
$upload->
getRealPath();
$file_uri =
$this->fileSystem->
getDestinationFilename($file_uri, FileSystemInterface::EXISTS_RENAME
);
// Lock based on the prepared file URI.
$lock_id =
$this->
generateLockIdFromFileUri($file_uri);
if (!
$this->lock->
acquire($lock_id)) { throw new HttpException(503,
sprintf('File "%s" is already locked for writing.',
$file_uri), NULL,
['Retry-After' => 1
]);
} // Begin building file entity.
$file = File::
create([]);
$file->
setOwnerId($this->currentUser->
id());
$file->
setFilename($prepared_filename);
$file->
setMimeType($this->mimeTypeGuesser->
guessMimeType($prepared_filename));