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",
"client_email": "...@...gserviceaccount.com",
"client_id": "...apps.googleusercontent.com",
"type": "service_account"
});
AuthClient client = await clientViaServiceAccount(
accountCredentials,
['https://www.googleapis.com/auth/drive']);
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.
What could be the problem? How could I test what happens, what is the exact response?
My solution is from: Dart: upload .jpg file to google Drive
Thanks, IMozes