nextcloud_webdav_client
NextCloud WebDAV Client
Seamless NextCloud integration for Drupal via WebDAV protocol
The NextCloud WebDAV Client module provides integration between Drupal and NextCloud servers using the WebDAV protocol. This module enables you to create folders, upload files, and manage content directly from your Drupal application to your NextCloud instance.
Features
- Folder Management - Create single folders or nested folder structures
- File Upload - Upload files from local filesystem or Drupal file entities
- Content Upload - Upload text content directly as files
- Directory Listing - List files and folders with metadata
- Batch Operations - Upload multiple files at once
- Configuration Management - Easy admin interface with connection testing
- Comprehensive Logging - Detailed logging and debugging tools
Requirements
- Drupal 10 or 11
- NextCloud server with WebDAV enabled
- Valid NextCloud user credentials or app passwords
- HTTPS connection (recommended for production)
Installation
Via Composer (Recommended)
composer require drupal/nextcloud_webdav_clientEnable and Configure
- Enable the module:
drush en nextcloud_webdav_client - Configure connection settings at
/admin/config/services/nextcloud-webdav - Test your connection using the built-in test interface
Configuration
Navigate to Administration > Configuration > Web Services > NextCloud WebDAV to configure:
Connection Settings
- Server URL: Your NextCloud server URL (e.g., https://cloud.example.com)
- Username: Your NextCloud username
- Password: NextCloud password or app password (recommended)
- Base Path: WebDAV base path (usually /remote.php/dav/files/)
Advanced Settings
- Timeout: Request timeout in seconds (default: 30)
- Verify SSL: SSL certificate verification (recommended: enabled)
Usage Examples
Using the Manager Service
// Get the manager service $webdav_manager = \Drupal::service('nextcloud_webdav_client.manager'); // Create a folder $webdav_manager->createFolder('my-folder/subfolder'); // Upload a Drupal file entity $file = File::load($file_id); $webdav_manager->uploadDrupalFile($file, 'uploads/myfile.pdf'); // Upload content as a file $content = "Hello, NextCloud!"; $webdav_manager->uploadContent($content, 'messages/hello.txt'); // List directory contents $items = $webdav_manager->listDirectory('my-folder');
Custom Module Integration
/** * Implements hook_file_insert(). */ function mymodule_file_insert(FileInterface $file) { $webdav_manager = \Drupal::service('nextcloud_webdav_client.manager'); if ($webdav_manager->isConfigured()) { // Auto-upload files to NextCloud $remote_path = 'drupal-uploads/' . $file->getFilename(); $webdav_manager->uploadDrupalFile($file, $remote_path); } }
API Reference
NextCloudWebDavManager
The main service for high-level operations:
isConfigured()- Check if module is configuredtestConnection()- Test connection to NextCloudcreateFolder(string $path)- Create folder(s)uploadDrupalFile(FileInterface $file, string $remote_path, bool $create_folders)- Upload Drupal fileuploadFile(string $local_path, string $remote_path, bool $create_folders)- Upload local fileuploadContent(string $content, string $remote_path, bool $create_folders)- Upload content as filelistDirectory(string $path)- List directory contentsuploadMultipleFiles(array $files, bool $create_folders)- Batch upload files
NextCloudWebDavClient
The low-level WebDAV client service:
testConnection()- Test WebDAV connectioncreateFolder(string $path)- Create single folderuploadFile(string $local_path, string $remote_path)- Upload fileuploadContent(string $content, string $remote_path)- Upload contentlistDirectory(string $path)- List directory
Security Considerations
Important: Follow these security best practices:
- Use NextCloud app passwords instead of your main password
- Create dedicated service accounts with minimal permissions
- Enable HTTPS everywhere
- Keep the "Verify SSL" option enabled in production
- Regular password rotation
Creating NextCloud App Passwords
- Log into your NextCloud web interface
- Go to Settings > Personal > Security
- Scroll to "App passwords" section
- Enter a name (e.g., "Drupal WebDAV") and click "Create new app password"
- Copy the generated password and use it in the module configuration
Troubleshooting
Connection Issues
- Verify server URL is correct and accessible
- Check username and password/app password
- Ensure NextCloud WebDAV is enabled
- Check SSL certificate issues
Upload Issues
- Verify file permissions on local files
- Check NextCloud storage quota
- Ensure target directory exists or enable folder creation
Debugging
Enable logging and check Reports > Recent log messages for detailed error information. Use the test interface at /admin/config/services/nextcloud-webdav/test for debugging.
Permissions
The module defines two permissions:
- Administer NextCloud WebDAV - Configure connection settings
- Use NextCloud WebDAV - Use WebDAV functionality and test interface
Testing Interface
Visit /admin/config/services/nextcloud-webdav/test to access the testing interface where you can:
- Create folders
- Upload files via web interface
- Upload text content
- List directory contents
- Debug WebDAV responses
Contributing
This module follows Drupal coding standards and best practices. When contributing:
- Follow Drupal coding standards
- Add appropriate documentation
- Include error handling and logging
- Write tests for new functionality
License: GPL v2 or later