Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/src/utils/solid_file_operations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,13 @@ class SolidFileOperations {
static Future<void> uploadFile(
BuildContext context,
String currentPath, {
String? basePath,
VoidCallback? onSuccess,
}) =>
SolidFileUploadOperations.uploadFile(
context,
currentPath,
basePath: basePath,
onSuccess: onSuccess,
);
}
34 changes: 28 additions & 6 deletions lib/src/utils/solid_file_operations_upload.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class SolidFileUploadOperations {
static Future<void> uploadFile(
BuildContext context,
String currentPath, {
String? basePath,
VoidCallback? onSuccess,
}) async {
try {
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions lib/src/widgets/solid_file.dart
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ class _SolidFileState extends State<SolidFile> {
context,
_currentPath,
_browserKey,
basePath: _effectiveBasePath,
);
}

Expand Down
6 changes: 4 additions & 2 deletions lib/src/widgets/solid_file_callbacks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,15 @@ class SolidFileDefaultCallbacks {
static SolidFileUploadCallbacks createUploadCallbacks(
BuildContext context,
String currentPath,
GlobalKey<SolidFileBrowserState> browserKey,
) {
GlobalKey<SolidFileBrowserState> browserKey, {
String? basePath,
}) {
return SolidFileUploadCallbacks(
onUpload: () {
SolidFileOperations.uploadFile(
context,
currentPath,
basePath: basePath,
onSuccess: () {
// Refresh the file browser after successful upload.

Expand Down