Skip to content

Commit

Permalink
Improve google drive upload (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-pratik-k authored Feb 27, 2024
1 parent 7b48081 commit d6a9120
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class LocalMediasViewStateNotifier extends StateNotifier<LocalMediasViewState> {
state =
state.copyWith(uploadingMedias: state.selectedMedias, error: null);
final folderId = await _googleDriveService.getBackupFolderId();

for (final media in state.selectedMedias) {
await _googleDriveService.uploadInGoogleDrive(
media: media, folderID: folderId!);
Expand Down
7 changes: 4 additions & 3 deletions data/lib/services/google_drive_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ class GoogleDriveService {
final driveApi = await _getGoogleDriveAPI();

final response = await driveApi.files.list(
q: "name='$_backUpFolderName' and description='$_backUpFolderDescription' and mimeType='application/vnd.google-apps.folder'",
q: "name='$_backUpFolderName' and mimeType='application/vnd.google-apps.folder'",
);

if (response.files?.isNotEmpty ?? false) {
if (response.files?.isNotEmpty ?? false || response.files?.first.trashed == false) {
return response.files?.first.id;
} else {
final folder = drive.File(
Expand All @@ -60,14 +60,15 @@ class GoogleDriveService {

final file = drive.File(
name: media.name ?? localFile.path.split('/').last,
id: media.id,
description: media.path,
parents: [folderID],
);
await driveApi.files.create(
file,
uploadMedia: drive.Media(localFile.openRead(), localFile.lengthSync()),
);
} catch (error) {
print(error);
throw AppError.fromError(error);
}
}
Expand Down

0 comments on commit d6a9120

Please sign in to comment.