// 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));
$file->
setFileUri($temp_file_path);
// Set the size. This is done in File::preSave() but we validate the file
// before it is saved.
$file->
setSize(@
filesize($temp_file_path));
// Validate the file against field-level validators first while the file is
// still a temporary file. Validation is split up in 2 steps to be the same
// as in \Drupal\file\Upload\FileUploadHandler::handleFileUpload().
// For backwards compatibility this part is copied from ::validate() to
// leave that method behavior unchanged.
// @todo Improve this with a file uploader service in