import 'dart:convert'; import 'dart:io'; import 'package:image_picker/image_picker.dart'; import 'package:uuid/uuid.dart'; import 'package:fis_common/logger/logger.dart'; import 'package:universal_html/html.dart' as html; abstract class UploadUtils { static XFile? convertBase64ToXFile(String base64Stirng) { try { final bytes = base64Decode(base64Stirng); final tempDir = Directory.systemTemp; final tempPath = tempDir.path; final imageId = const Uuid().v4().replaceAll('-', ''); final filePath = '$tempPath/$imageId'; File(filePath).writeAsBytesSync(bytes); return XFile(filePath); } catch (e) { print('Error converting base64 to XFile: $e'); logger.i('Error converting base64 to XFile: $e'); return null; } } static html.File? convertBase64ToFile(String base64Image) { try { final bytes = base64Decode(base64Image); const mimeType = 'image/jpeg'; // 替换为您的图片类型 final blob = html.Blob([bytes], mimeType); final file = html.File([blob], 'image.jpg'); // 替换为您的文件名 return file; } catch (e) { print('Error converting base64 to File: $e'); return null; } } }