This commit is contained in:
Leon Bösche
2026-01-09 23:57:29 +01:00
parent 4f67ead22d
commit 260b8b180e
2 changed files with 20 additions and 12 deletions

View File

@@ -24,8 +24,12 @@ class UploadBloc extends Bloc<UploadEvent, UploadState> {
for (final file in event.files) {
try {
print('[UploadBloc] Starting upload for ${file.name} to orgId=${event.orgId}, path=${file.path}');
print('[UploadBloc] File bytes: ${file.bytes?.length ?? 0} bytes, localPath: ${file.localPath}');
print(
'[UploadBloc] Starting upload for ${file.name} to orgId=${event.orgId}, path=${file.path}',
);
print(
'[UploadBloc] File bytes: ${file.bytes?.length ?? 0} bytes, localPath: ${file.localPath}',
);
// Simulate upload
await _fileRepository.uploadFile(event.orgId, file);
print('[UploadBloc] Upload successful for ${file.name}');

View File

@@ -52,11 +52,17 @@ class FileService {
// If bytes or localPath available, send multipart upload with field 'file'
final Map<String, dynamic> fields = {'path': file.path};
FormData formData;
print('[FileService] uploadFile: file=${file.name}, path=${file.path}, orgId=$orgId');
print('[FileService] bytes=${file.bytes?.length ?? 0}, localPath=${file.localPath}');
print(
'[FileService] uploadFile: file=${file.name}, path=${file.path}, orgId=$orgId',
);
print(
'[FileService] bytes=${file.bytes?.length ?? 0}, localPath=${file.localPath}',
);
if (file.bytes != null) {
print('[FileService] Using bytes for upload (${file.bytes!.length} bytes)');
print(
'[FileService] Using bytes for upload (${file.bytes!.length} bytes)',
);
formData = FormData.fromMap({
...fields,
'file': MultipartFile.fromBytes(file.bytes!, filename: file.name),
@@ -69,7 +75,9 @@ class FileService {
});
} else {
// Fallback to metadata-only create (folders or client that can't send file content)
print('[FileService] No bytes or localPath; falling back to metadata-only');
print(
'[FileService] No bytes or localPath; falling back to metadata-only',
);
final data = {
'name': file.name,
'path': file.path,
@@ -90,11 +98,7 @@ class FileService {
final endpoint = orgId.isEmpty ? '/user/files' : '/orgs/$orgId/files';
print('[FileService] Uploading to endpoint: $endpoint');
await _apiClient.post(
endpoint,
data: formData,
fromJson: (d) => null,
);
await _apiClient.post(endpoint, data: formData, fromJson: (d) => null);
print('[FileService] Upload completed for ${file.name}');
}