upload.dart 743 B

1234567891011121314151617181920212223242526
  1. import 'dart:convert';
  2. import 'dart:io';
  3. import 'package:image_picker/image_picker.dart';
  4. import 'package:uuid/uuid.dart';
  5. import 'package:fis_common/logger/logger.dart';
  6. abstract class UploadUtils {
  7. static XFile? convertBase64ToXFile(String base64Stirng) {
  8. try {
  9. final bytes = base64Decode(base64Stirng);
  10. final tempDir = Directory.systemTemp;
  11. final tempPath = tempDir.path;
  12. final imageId = const Uuid().v4().replaceAll('-', '');
  13. final filePath = '$tempPath/$imageId';
  14. File(filePath).writeAsBytesSync(bytes);
  15. return XFile(filePath);
  16. } catch (e) {
  17. print('Error converting base64 to XFile: $e');
  18. logger.i('Error converting base64 to XFile: $e');
  19. return null;
  20. }
  21. }
  22. }