0

I do not need to get the content of the file, I just need ID only! If this is impossible then the impossibility should be the answer.

I get the content URI from android intent ACTION_GET_CONTENT using flutter plugin file_picker.

It work perfectly, but I need to get the selected document ID (spreadsheet ID, specifically) in Google Drive.

The URI I got looks like:

content://com.google.android.apps.docs.storage/document/acc%3D1%3Bdoc%3Dencoded%3DBEskNs6jf7jS24J%2FMnNdnr7fDrih03xNetfcCUsggemjSmpiWBC5

After using URL decoded it turns out to be like:

content://com.google.android.apps.docs.storage/document/acc=1;doc=encoded=BEskNs6jf7jS24J/MnNdnr7fDrih03xNetfcCUsggemjSmpiWBC5

The link provided by Google Drive API v3: get FileID from Android content URI

Is it possible to get the document ID from this URI? I have tried base64 decode, not working.

Or any suggestion to get the ID? Maybe create a custom UI showing documents and let user select?

My application helps edit spreadsheet by user selected. Here is some code to reproduce:

// The package will use Intent in android
final result = await FilePicker.platform.pickFiles();
// Should check null
final file = result!.files.first;
// Content URI
print(file.identity);
// File name
print(file.name);
Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
呂學洲
  • 1,123
  • 8
  • 19
  • Please include [example] – Linda Lawton - DaImTo Mar 27 '22 at 20:46
  • Done, using [package](https://pub.dev/packages/file_picker) make the code so easy that I'm not sure it is useful. – 呂學洲 Mar 27 '22 at 22:04
  • so what does print(file.id); do exactly? – Linda Lawton - DaImTo Mar 28 '22 at 06:16
  • Do you mean `identity`? It is the URI(`content://com.google...`) from [selected data](https://github.com/miguelpruivo/flutter_file_picker/blob/443808b9cd350f8224169a2ebc5ceb555e2772d8/android/src/main/java/com/mr/flutter/plugin/filepicker/FilePickerDelegate.java#L96). – 呂學洲 Mar 28 '22 at 10:42
  • I found alternative solution: using [file's name to get ID by Driver API](https://stackoverflow.com/questions/43345575/find-a-google-drive-sheet-by-name-using-api-4-in-android) – 呂學洲 Apr 02 '22 at 07:09

0 Answers0