6
votes

I need to allow user to select which Google Drive folder to upload their files.

I am using this code now:

view = new google.picker.DocsView(google.picker.ViewId.FOLDERS).
  setParent('root').
  setSelectFolderEnabled(true)

picker = new google.picker.PickerBuilder().
  addView(view).
  setSelectableMimeTypes('application/vnd.google-apps.folder').
  enableFeature(google.picker.Feature.NAV_HIDDEN).
  setOAuthToken(token).
  setDeveloperKey(key).
  setAppId(appid).
  setCallback(picker_callback).
  build()

But there are a few problems here:

  1. User still see files despite that google.picker.ViewId.FOLDERS is used
  2. There is no way to select root folder

Is any way to fix my problems?

Currently files are always upload to root folder, I don't want this new feature remove this possibility.

2
you could have your UX default to root and offer a "select folder" button to bring the picker up.Zig Mandel
If you select one of the files in the root folder and click Select, it saves to the root folder. Bad UX design from Google, but it works. Unless your root folder is empty. Then you're out of luck.Juan Ferrer

2 Answers

1
votes

Unfortunately this only answers the first question/problem.

You can specify the mime-type for the view, as well as for the picker:

var view = new google.picker.DocsView(google.picker.ViewId.FOLDERS);
view.setMimeTypes('application/vnd.google-apps.folder');
view.setSelectFolderEnabled(true);

As far as I know there's no way to select the root, so you have to get your user to make a UI choice beforehand.

0
votes

Use .setParent('root') of the DocView class , see full answer here https://stackoverflow.com/a/50689380/1226748