idle4000
This commit is contained in:
@@ -24,8 +24,12 @@ class UploadBloc extends Bloc<UploadEvent, UploadState> {
|
|||||||
|
|
||||||
for (final file in event.files) {
|
for (final file in event.files) {
|
||||||
try {
|
try {
|
||||||
print('[UploadBloc] Starting upload for ${file.name} to orgId=${event.orgId}, path=${file.path}');
|
print(
|
||||||
print('[UploadBloc] File bytes: ${file.bytes?.length ?? 0} bytes, localPath: ${file.localPath}');
|
'[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
|
// Simulate upload
|
||||||
await _fileRepository.uploadFile(event.orgId, file);
|
await _fileRepository.uploadFile(event.orgId, file);
|
||||||
print('[UploadBloc] Upload successful for ${file.name}');
|
print('[UploadBloc] Upload successful for ${file.name}');
|
||||||
|
|||||||
@@ -52,11 +52,17 @@ class FileService {
|
|||||||
// If bytes or localPath available, send multipart upload with field 'file'
|
// If bytes or localPath available, send multipart upload with field 'file'
|
||||||
final Map<String, dynamic> fields = {'path': file.path};
|
final Map<String, dynamic> fields = {'path': file.path};
|
||||||
FormData formData;
|
FormData formData;
|
||||||
print('[FileService] uploadFile: file=${file.name}, path=${file.path}, orgId=$orgId');
|
print(
|
||||||
print('[FileService] bytes=${file.bytes?.length ?? 0}, localPath=${file.localPath}');
|
'[FileService] uploadFile: file=${file.name}, path=${file.path}, orgId=$orgId',
|
||||||
|
);
|
||||||
|
print(
|
||||||
|
'[FileService] bytes=${file.bytes?.length ?? 0}, localPath=${file.localPath}',
|
||||||
|
);
|
||||||
|
|
||||||
if (file.bytes != null) {
|
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({
|
formData = FormData.fromMap({
|
||||||
...fields,
|
...fields,
|
||||||
'file': MultipartFile.fromBytes(file.bytes!, filename: file.name),
|
'file': MultipartFile.fromBytes(file.bytes!, filename: file.name),
|
||||||
@@ -69,7 +75,9 @@ class FileService {
|
|||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// Fallback to metadata-only create (folders or client that can't send file content)
|
// 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 = {
|
final data = {
|
||||||
'name': file.name,
|
'name': file.name,
|
||||||
'path': file.path,
|
'path': file.path,
|
||||||
@@ -90,11 +98,7 @@ class FileService {
|
|||||||
|
|
||||||
final endpoint = orgId.isEmpty ? '/user/files' : '/orgs/$orgId/files';
|
final endpoint = orgId.isEmpty ? '/user/files' : '/orgs/$orgId/files';
|
||||||
print('[FileService] Uploading to endpoint: $endpoint');
|
print('[FileService] Uploading to endpoint: $endpoint');
|
||||||
await _apiClient.post(
|
await _apiClient.post(endpoint, data: formData, fromJson: (d) => null);
|
||||||
endpoint,
|
|
||||||
data: formData,
|
|
||||||
fromJson: (d) => null,
|
|
||||||
);
|
|
||||||
print('[FileService] Upload completed for ${file.name}');
|
print('[FileService] Upload completed for ${file.name}');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user