How to create folder using google drive api in a flutter app?
1,639
As you have already done Auth credentials
, you can use this
Simple function to create folder in Google Drive.
clientViaServiceAccount(credentials, scopes).then((http_client) async {
var _drive = v3.DriveApi(http_client);
var _createFolder = await _drive.files.create(
v3.File()
..name = 'FileName'
..parents = ['1f4tjhpBJwF5t6FpYvufTljk8Gapbwajc'] // Optional if you want to create subfolder
..mimeType = 'application/vnd.google-apps.folder', // this defines its folder
);
});
Author by
Antoun
Updated on December 12, 2022Comments
-
Antoun over 1 year
I have tried to create folder in a
flutter app
in agoogle drive account
. It shows me abad argument(s) error
. Although i am working with the documentation examplesHere is the code i have tried to do. it generates
"Bad argument(s)" error.
final _SCOPES = [drive.DriveApi.DriveScope]; void adrive(){ clientViaServiceAccount(_credentials,_SCOPES).then(onValue).catchError((e)=>print(e)); } FutureOr onValue(AuthClient client) { //drive.DriveApi(client).files.list().then((value)=>print(value.items[0])); // The previous line works fine drive.File r = new drive.File(); r.mimeType = "application/vnd.google-apps.folder"; r.title = "hello"; drive.DriveApi(client).files.insert(r,uploadOptions: commons.UploadOptions.Resumable).then((f)=>print(f.mimeType+" "+f.originalFilename)) .catchError((ex)=>print(ex.toString()));
-
sameer kashyap over 3 yearsI'm unable to create a folder and upload a file to it, the above code does not work, can you help me? I get an Exception telling me the file is not found, which is specified in the parents property