How can I update google drive file in flutter?
Issue:
As the error you're getting says, you are trying to update properties which are not directly writable.
Explanation:
Not all properties in the Files resource
can be updated via Files: update. You can check which ones can and which ones cannot by looking at the properties list in the File resource page: the ones that can be directly updated are marked as writable
on the Notes field. If you scroll down to the property shared
, you will notice that it's not writable
, and that's the reason you're getting this error.
The reason shared
is not writable
is that file sharing is not managed by the File resource
, but by the Permissions resource. Files can be shared via Permissions: create (in which you have to specify who you're sharing the file with, and which role will be granted by this permission (view access, edit access, etc.).
Once the file has been shared (via Permissions: create
, or directly through Drive UI), the property shared
will automatically become true
.
Reference:
Soe San
Updated on December 21, 2022Comments
-
Soe San over 1 year
I want to update drive files to
shared = true
. but I get this error. How can I fix it?E/flutter (14758): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: DetailedApiRequestError (status: 403, message: The resource body includes fields which are not directly writable.)
Future update() async { var client = await getHttpClient(); var drive = ga.DriveApi(client); print("Uploading file"); var metadata = new ga.File(); metadata..shared = true; metadata..name = 'sst'; var response = await drive.files.update(metadata, '1633r8UpI6gmJKtosLju3ThCQ2YR5AzKa'); print("Result ${response.toJson()}"); }
-
Soe San almost 4 yearsThank you so much.Your answer is great.