idle4000
This commit is contained in:
@@ -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}');
|
||||
|
||||
@@ -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}');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user