protected function generateKey(File $file, AttachableObjectInterface $object, $fieldName)
    {
        $schema = $this->getSchemaForObject($object, $fieldName);
        
        if ($file instanceof UploadedFile)
        {
            $extension = $file->getClientOriginalExtension();
        }
        else
        {
            $extension = $file->getExtension();
        }
        
        $hash = $this->generateFileHash($file, $schema);
        
        $fileKey = new $this->fileKeyClass();
        $fileKey
            ->setHash($hash)
            ->setExtension($extension)
            ->setDepth($schema->getStorageDepth())
            ->setClassName($object->getAttachableClassName())
            ->setFieldName($fieldName)
            ->setStorageName($schema->getStorage()->getName())
        ;
        
        // This triggers the generation inside the key. If there are any exceptions, we want them here for clarity.
        $fileKey->getKey();
        
        return $fileKey;
    }