Example or template on how to do file upload in Go

2020-02-13 06:32发布

问题:

can anyone share with me the .zip file for Document Approval template because I can't open it since I'm not using GCS but I wanted to go through how they using Drive Picker widget to upload file and so on.

another thing is, where the file will be uploaded to? is it the owner's Drive? is it possible to upload the document to a single folder of a Team Drive instead? Really appreciate it if anyone can share with me some thoughts or any API will do, Thanks!

回答1:

The only way to upload files that App Maker provides out of the box is Drive Picker widget and by default it uploads files to current user's Drive root folder. Drive Picker's API allows to change default upload folder, however App Maker doesn't expose the setting at this time. But it has onPickerInit event that provides you with pickerBuilder that you can use to customize your the picker:

// onPickerInit Drive Picker's event handler
var uploadView = new google.picker.DocsUploadView();
uploadView.setParent('ID of the folder to upload to');

pickerBuilder.addView(uploadView);

This trick works both for personal and Team Drive folders.

Note

It seems that setParent works only in combination with MULTISELECT_ENABLED drive picker feature enabled.



回答2:

Right now, looks appmaker seems to ALWAYS adds an upload tab itself, so if I add another uploadview, I end up with two upload tabs, the first one uploading to the main folder and selected by default :(

My best guess for a workaround is to not add my own upload view, let the picker upload the file to the main folder, and move the file in the onSelect hook to its final destination. If there's a better way, I'd love the hear.