Reputation: 1735
The Problem
I'm using Google Drive to store application-specific data. I can read and write data to my drive buy whenever I want to update the config in the drive a new file is created instead of updating the old one.
I have tried the following:
Unhandled Exception: DetailedApiRequestError(status: 400, message: The provided file ID is not usable.)
Unhandled Exception: DetailedApiRequestError(status: 409, message: A file already exists with the provided ID.)
My Code:
final signIn.GoogleSignInAccount account = await _googleSignIn.signIn();
final authHeaders = await account.authHeaders;
final authenticateClient = GoogleAuthClient(authHeaders);
final driveApi = drive.DriveApi(authenticateClient);
File _data = await _report.backupData(); //gets data to be overwriten
final Stream<List<int>> mediaStream = _data.openRead();
var media = new drive.Media(mediaStream, _data.lengthSync());
var driveFile = new drive.File();
driveFile.parents=['appDataFolder'];
driveFile.name = "backup.mw";
final result = await driveApi.files.create(driveFile, uploadMedia: media,);
print("Upload result: ${result.id}");
Upvotes: 3
Views: 961
Reputation: 117016
The code you are using does a files.create file create will create a new file every time it is run.
final result = await driveApi.files.create(driveFile, uploadMedia: media,);
If you want to update an existing file then you will need to do Files.update
Upvotes: 2