javascriptgoogle-picker

Google picker upload


I am trying to make a picker of Google drive that let me to upload new local files to Google Drive. The picker is working and it is showing me my Google Drive files, but there's only the select button and there's not a "upload" button. I added the view google.picker.DocsUploadView() but still not a button.

There it is my createPicker function:

function createPicker() {
  if (pickerApiLoaded && oauthToken) {
    var view = new google.picker.View(google.picker.ViewId.DOCS);
    view.setMimeTypes("image/png,image/jpeg,image/jpg");
    var picker = new google.picker.PickerBuilder()
        .enableFeature(google.picker.Feature.NAV_HIDDEN)
        .enableFeature(google.picker.Feature.MULTISELECT_ENABLED)
        .setAppId(appId)
        .setOAuthToken(oauthToken)
        .addView(view)
        .addView(new google.picker.DocsUploadView())
        .setDeveloperKey(developerKey)
        .setCallback(pickerCallback)
        .build();
     picker.setVisible(true);
  }
}  

Any thoughts?


Solution

  • You'll be using DocsUploadView.

    Use this in your createPicker code:

    function createPicker() {
        // Create a view to search images.
        var view = new google.picker.View(google.picker.ViewId.DOCS);
        view.setMimeTypes('image/png,image/jpeg');
    
        // Use DocsUploadView to upload documents to Google Drive.
        var uploadView = new google.picker.DocsUploadView();
    
        var picker = new google.picker.PickerBuilder().
            addView(view).
            addView(uploadView).
            setAppId(appId).
            setOAuthToken(oauthToken).
            setCallback(pickerCallback).
            build();
        picker.setVisible(true);
    }
    
     // A simple callback implementation.
    function pickerCallback(data) {
        if (data.action == google.picker.Action.PICKED) {
            var fileId = data.docs[0].id;
            alert('The user selected: ' + fileId);
            createPicker();
        }
    }
    

    It will look like this. enter image description here