Hi,
I am trying to upload some pictures taken in my application to Google Drive.
I created a project and a Service account key and I have Google Drive API enabled.
My code snippet looks like this:
...
// sfilePath = "/storage/emulated/0/Xyz";
// sfileName = "PIC_17";
final accountCredentials = new ServiceAccountCredentials.fromJson({
"private_key_id": "...",
"private_key": "-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n",
"type": "service_account"
});
AuthClient client = await clientViaServiceAccount(
accountCredentials,
var driveApi = ga.DriveApi(client);
var fileToUpload = File(sfilePath + sfileName + '.jpg');
var response = await driveApi.files.create(ga.File()..name = 'my_file.jpg',
uploadMedia: ga.Media(fileToUpload.openRead(), fileToUpload.lengthSync()));
print(response.toJson());
...
After running the program print(response.toJson()) results in: {id: ..., kind: drive#file, mimeType: image/jpeg, name: my_file.jpg}
and I see the Requests number for Google Drive API on Dashboard increasing after a while, but I can't find my_file.jpg on my Google Drive.
Thanks for any suggestions,
IMozes