AppMaker and picker widget - uploading to a specif

2019-06-01 18:11发布

问题:

I'm trying to have a button to allow users to upload a file, into a specific folder. I tried to follow other advise, and add this hook to

onPickerInit:

var uploadView = new google.picker.DocsUploadView()
uploadView.setParent('XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'); // test folder

pickerBuilder.addView(uploadView);

I've set the MULTISELECT_ENABLED feature (without it, the destination folder is not respected), and I can in fact now upload the files where they belong. Yay!

HOWEVER: The picker widget now has two upload tabs. The first one just does the regular upload into the drive main folder, the second tab does the right thing. My guess is that appmaker contstructs the first upload tab behind the curtains and there is no feature to disable this.

This is obviously fairly quirky and hardly usable. My questions are:

1) are there (possibly undocumented) API calls in the pickerbuilder to remove the original upload view?

2) Is it possible to respect the destination folder even is the MULTISELECT feature is off ?

Many thanks in advance for any pragmatic solutions!

回答1:

To answer your questions directly:

1.) YES
2.) YES

Now, let's dig a little bit into what's happening under the hood. You are right:

My guess is that appmaker contstructs the first upload tab behind the curtains and there is no feature to disable this.

However, we can manipulate the object. So instead of creating a new picker view, let's simply configure the default one to upload the files to the folder you want. We can achieve that by doing the following:

1.) After you insert a Drive Picker into your UI, make sure the Drive Picker Properties are all empty:

2.) Next, go to the event handlers and click on the onPickerInit event handler. Type in this code:

var folderId = "10fYS3l32R6gk79POOSS8X_Vbsz7vqzRWX"; //the desired folder id
pickerBuilder.SW.Vq["0"].mc.parent = folderId; 

In summary, I've come to the conclusion that the property SW contains the array of drive views, which are saved under the property Vq. Vq["0"] is the first view in the array of views and the mc property contains the features; hence parent = folderId.

I hope this makes sense and it helps you!