Skip to content

Commit

Permalink
Trying to handle case when the same file is already uploaded #53 #38
Browse files Browse the repository at this point in the history
  • Loading branch information
MrCsabaToth committed Sep 22, 2024
1 parent c79ac9e commit 52a598f
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lib/ai/service/ai_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,15 @@ class AiService with FirebaseMixin, ToolsMixin {
debugPrint('medium: ${mediumFile.xFile.path} (${mediumFile.mimeType})');
if (!mediumFile.mimeTypeIsUnknown()) {
final fileName = mediumFile.xFile.path.split('/').last;
final uploadTask = await FirebaseStorage.instance
.ref(fileName)
.putFile(mediumFile.file);
final fileUri = 'gs://$bucket/${uploadTask.ref.fullPath}';
final fileRef = FirebaseStorage.instance.ref(fileName);
try {
// Check if already uploaded
await fileRef.getDownloadURL();
} on FirebaseException {
// Not uploaded yet
await fileRef.putFile(mediumFile.file);
}
final fileUri = 'gs://$bucket/${fileRef.fullPath}';
debugPrint('Storage URI: $fileUri');
parts.add(FileData(mediumFile.mimeType, fileUri));
}
Expand Down

0 comments on commit 52a598f

Please sign in to comment.