diff --git a/lib/src/utils/solid_file_operations.dart b/lib/src/utils/solid_file_operations.dart index 27f00ba..97a0c5e 100644 --- a/lib/src/utils/solid_file_operations.dart +++ b/lib/src/utils/solid_file_operations.dart @@ -78,11 +78,13 @@ class SolidFileOperations { static Future uploadFile( BuildContext context, String currentPath, { + String? basePath, VoidCallback? onSuccess, }) => SolidFileUploadOperations.uploadFile( context, currentPath, + basePath: basePath, onSuccess: onSuccess, ); } diff --git a/lib/src/utils/solid_file_operations_upload.dart b/lib/src/utils/solid_file_operations_upload.dart index 190d087..f4c82b9 100644 --- a/lib/src/utils/solid_file_operations_upload.dart +++ b/lib/src/utils/solid_file_operations_upload.dart @@ -49,6 +49,7 @@ class SolidFileUploadOperations { static Future uploadFile( BuildContext context, String currentPath, { + String? basePath, VoidCallback? onSuccess, }) async { try { @@ -102,16 +103,37 @@ class SolidFileUploadOperations { final remoteFileName = '$sanitizedFileName.enc.ttl'; - // Determine upload path. + // Calculate upload path relative to the base path. String uploadPath = remoteFileName; if (currentPath.isNotEmpty && currentPath != '/') { - // Remove leading slash if present. + String relativePath = currentPath; - final cleanPath = currentPath.startsWith('/') - ? currentPath.substring(1) - : currentPath; - uploadPath = '$cleanPath/$remoteFileName'; + // Strip the base path from current path to get the relative path. + + if (basePath != null && basePath.isNotEmpty) { + if (currentPath.startsWith(basePath)) { + relativePath = currentPath.substring(basePath.length); + + // Remove leading slash if present after stripping. + + if (relativePath.startsWith('/')) { + relativePath = relativePath.substring(1); + } + } + } else { + // Remove leading slash if present. + + if (relativePath.startsWith('/')) { + relativePath = relativePath.substring(1); + } + } + + // Only prepend relative path if it's not empty. + + if (relativePath.isNotEmpty) { + uploadPath = '$relativePath/$remoteFileName'; + } } if (!context.mounted) return; diff --git a/lib/src/widgets/solid_file.dart b/lib/src/widgets/solid_file.dart index f50b61c..cbbd2aa 100644 --- a/lib/src/widgets/solid_file.dart +++ b/lib/src/widgets/solid_file.dart @@ -283,6 +283,7 @@ class _SolidFileState extends State { context, _currentPath, _browserKey, + basePath: _effectiveBasePath, ); } diff --git a/lib/src/widgets/solid_file_callbacks.dart b/lib/src/widgets/solid_file_callbacks.dart index 2c6454f..f875dad 100644 --- a/lib/src/widgets/solid_file_callbacks.dart +++ b/lib/src/widgets/solid_file_callbacks.dart @@ -42,13 +42,15 @@ class SolidFileDefaultCallbacks { static SolidFileUploadCallbacks createUploadCallbacks( BuildContext context, String currentPath, - GlobalKey browserKey, - ) { + GlobalKey browserKey, { + String? basePath, + }) { return SolidFileUploadCallbacks( onUpload: () { SolidFileOperations.uploadFile( context, currentPath, + basePath: basePath, onSuccess: () { // Refresh the file browser after successful upload.