diff --git a/lib/screens/garage_screen.dart b/lib/screens/garage_screen.dart index cb5560b..c0167e8 100644 --- a/lib/screens/garage_screen.dart +++ b/lib/screens/garage_screen.dart @@ -678,14 +678,18 @@ class GarageScreenState extends State { showGlobalSnackBar('Uploading photo…'); final oldPath = car['user_image_url'] as String?; - final newPath = await StorageService.uploadCarImage( - file: File(xFile.path), - entryId: car['id'] as int, - oldPath: oldPath, - ); - - if (newPath == null) { - showGlobalSnackBar('Failed to upload photo.', isError: true); + String newPath; + try { + newPath = await StorageService.uploadCarImage( + file: File(xFile.path), + entryId: car['id'] as int, + oldPath: oldPath, + ); + } catch (e) { + showGlobalSnackBar( + 'Failed to upload photo. Please try a smaller/clearer image. ($e)', + isError: true, + ); return; } diff --git a/lib/services/storage_service.dart b/lib/services/storage_service.dart index edd3951..1273be4 100644 --- a/lib/services/storage_service.dart +++ b/lib/services/storage_service.dart @@ -18,34 +18,29 @@ class StorageService { /// Upload a car image for a specific hotwheels entry. /// Returns the storage path on success (e.g. `uid/123.jpg`). - static Future uploadCarImage({ + static Future uploadCarImage({ required File file, required int entryId, String? oldPath, }) async { - try { - if (oldPath != null && oldPath.isNotEmpty) { - await deleteCarImage(oldPath); - } - - final userId = supabase.auth.currentUser!.id; - final path = '$userId/$entryId.jpg'; - final compressed = await _compressImage(file); - - await supabase.storage.from(_bucket).uploadBinary( - path, - compressed, - fileOptions: const FileOptions( - upsert: true, - contentType: 'image/jpeg', - ), - ); - - return path; - } catch (e) { - debugPrint('StorageService.uploadCarImage error: $e'); - return null; + if (oldPath != null && oldPath.isNotEmpty) { + await deleteCarImage(oldPath); } + + final userId = supabase.auth.currentUser!.id; + final path = '$userId/$entryId.jpg'; + final compressed = await _compressImage(file); + + await supabase.storage.from(_bucket).uploadBinary( + path, + compressed, + fileOptions: const FileOptions( + upsert: true, + contentType: 'image/jpeg', + ), + ); + + return path; } /// Generates a temporary signed URL for a private image path.