I have successfully created a PikaCloudConnector in the connectors package that supports uploading files through the StorageApiController#Upload action. The implementation bypasses authorization and antiforgery token validation as requested.
connectors/PikaCloudConnector.go- Main connector implementationPikaCloudHandler.go- Integration with file watchertools/test_pikacloud.go- Test utility for the connectorconfig_with_pikacloud.json- Example configuration with PikaCloud settingsconnectors/README.md- Comprehensive documentation
Config.go- Added PikaCloud configuration supportMain.go- Integrated PikaCloud handler initializationFileWatcher.go- Added PikaCloud-enabled file watchingMakefile- Added build targets for tools
- ✅ HTTP Multipart Upload - Uploads files using multipart/form-data
- ✅ Retry Logic - Configurable retry attempts with exponential backoff
- ✅ Timeout Handling - Configurable request timeouts
- ✅ Custom Path Support - Upload files with custom target paths
- ✅ Connection Testing - Test connectivity to PikaCore API
- ✅ Error Handling - Comprehensive error handling and logging
- ✅ Background Uploads - Non-blocking uploads when integrated with file watcher
- ✅ File Watcher Integration - Seamless integration with existing file watcher
- ✅ Automatic Operations - Auto-upload on create, modify, rename events
- ✅ Path Mapping - Intelligent relative path calculation
- ✅ Dual Operation - Performs both local filesystem and cloud operations
- ✅ JSON Configuration - Easy configuration via JSON file
- ✅ Optional Integration - PikaCloud can be enabled/disabled
- ✅ Backward Compatibility - Existing configurations continue to work
The connector is designed to work with PikaCore's StorageApiController:
[HttpPost]
[ActionName("{bucketId}")]
public async Task<IActionResult> Upload(string bucketId)- Method: POST
- URL:
/Api/v1/Storage/{bucketId} - Content-Type:
multipart/form-data - Form Field: File content with field name as target path
- File Name: Original filename in form disposition
{
"detail": "Wgrano plik",
"cgid": "generated-guid",
"bucketId": "bucket-id",
"targetPath": "encoded-target-path"
}{
"folders": ["/home/ofca/sync"],
"workDir": "/home/ofca/sync",
"dstPath": "/mnt/public",
"pikaCloud": {
"baseUrl": "https://pikacore.example.com",
"bucketId": "12345678-1234-1234-1234-123456789012",
"timeout": 30,
"retryCount": 3
}
}config := connectors.PikaCloudConfig{
BaseURL: "https://pikacore.example.com",
BucketID: "your-bucket-id",
Timeout: 30,
RetryCount: 3,
}
connector := connectors.NewPikaCloudConnector(config)
response, err := connector.UploadFile("/path/to/file.txt")# Build test utility
make build-tools
# Test upload with auto-generated file
./tools/test_pikacloud -url https://pikacore.example.com -bucket your-bucket-id -test
# Test upload with specific file
./tools/test_pikacloud -url https://pikacore.example.com -bucket your-bucket-id -file /path/to/test.txt- Authorization bypassed - No authentication headers sent
- CSRF protection bypassed - No antiforgery tokens included
- TLS verification - Uses default Go HTTP client settings
For production deployment, consider implementing:
- Authentication (JWT, API keys, etc.)
- CSRF protection
- Custom TLS configuration
- Rate limiting compliance
- File Event → File watcher detects change
- Local Operation → Standard filesystem operation executed
- Cloud Upload → If PikaCloud enabled, file uploaded in background
- Logging → All operations logged for monitoring
# Build main service
make build
# Build test utilities
make build-tools
# Test configuration (replace with actual values)
./tools/test_pikacloud \
-url https://your-pikacore-instance.com \
-bucket your-bucket-id \
-test
# Run with PikaCloud enabled
./pikafileservice -c config_with_pikacloud.json -dThe implementation includes robust error handling for:
- Network connectivity issues
- HTTP errors (4xx/5xx responses)
- File system errors
- JSON parsing errors
- Timeout conditions
- Retry exhaustion
All errors are logged with appropriate detail levels for debugging.
The connector is ready for use with your PikaCore StorageApiController. To implement authentication and CSRF protection in the future:
- Add authentication header support to
PikaCloudConfig - Implement token acquisition/refresh logic
- Add antiforgery token handling
- Extend test utility to support authenticated testing
The current implementation provides a solid foundation that can be extended with security features when needed.