Google uploader selector

I am currently working on implementing a Google Drive picker that allows me to upload new local files to my Drive. The picker is functional and displaying my existing Google Drive files, but I am unable to find an "upload" button, even after adding the google.picker.DocsUploadView().

Below 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 suggestions or ideas for resolving this issue?

Answer №1

For the task at hand, utilize DocsUploadView.

Insert this snippet into your createPicker function:

function createPicker() {
    // Setting up a view to browse images.
    var view = new google.picker.View(google.picker.ViewId.DOCS);
    view.setMimeTypes('image/png,image/jpeg');

    // Incorporating DocsUploadView for uploading 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);
}

// Basic callback method.
function pickerCallback(data) {
    if (data.action == google.picker.Action.PICKED) {
        var fileId = data.docs[0].id;
        alert('The user selected: ' + fileId);
        createPicker();
    }
}

The visual representation will resemble this. https://i.sstatic.net/nnuzM.png

Answer №2

Within the documentation's demonstration, this particular line:

.enableFeature(google.picker.Feature.NAV_HIDDEN)

Serves to conceal the 'upload' button

Answer №3

The "Upload" option can be found within the "Navigation Pane", which you can conceal using the "google.picker.Feature.NAV_HIDDEN" attribute.

Answer №4

Can someone provide the missing part of the code?

An easy way to upload a file is by sending a simple upload request. This approach works best when:

-The file is small enough to be re-uploaded entirely if the connection fails. -There is no metadata to include. This could be the case if you plan to send metadata separately or if no metadata is available. To perform a simple upload, send a POST or PUT request to the method's /upload URI and add the query parameter uploadType=media. For instance:

POST https://www.googleapis.com/upload/drive/v3/files?uploadType=media

The necessary HTTP headers for a simple upload request are:

-Content-Type: Specify one of the approved media data types for the method as listed in the API reference. -Content-Length: Indicate the number of bytes being uploaded. Not needed for chunked transfer encoding. Example: Simple upload

The following example demonstrates a simple upload request for the Drive API.

POST /upload/drive/v3/files?uploadType=media HTTP/1.1

Host: www.googleapis.com

Content-Type: image/jpeg

Content-Length: number_of_bytes_in_file

Authorization: Bearer your_auth_token

The example pertains to JPEG data but content types can be adjusted or added.

To learn more, visit: https://developers.google.com/drive/v3/web/manage-uploads#simple

Answer №5

My understanding, based on information from Google Docs, suggests that in order to enable the upload tab, you need to incorporate the 'upload' view into your code. Here is an example of how I implemented this feature:

Be sure to replace 'YOUR_DEVELOPER_KEY_HERE' with your own developer key in the code below:

const googleViewId = google.picker.ViewId.DOCS;

/*code to create obj of DocsUploadView for upload*/
const uploadView = new google.picker.DocsUploadView();

const docsView = new google.picker.DocsView(googleViewId)
                    .setIncludeFolders(true)
                    .setSelectFolderEnabled(true);

const picker = new window.google.picker.PickerBuilder()
                .enableFeature(google.picker.Feature.SIMPLE_UPLOAD_ENABLED)
                  .enableFeature(google.picker.Feature.MULTISELECT_ENABLED)
                    .addView(docsView)
                    .addView(uploadView) /*DocsUploadView added*/
                    .setOAuthToken(oauthToken)
                    .setDeveloperKey('YOUR_DEVELOPER_KEY_HERE')
                    .setCallback((data)=>{
                      if (data.action == google.picker.Action.PICKED) {
                          var fileId = data.docs[0].id;
                          alert('The user selected: ' + fileId);
                          picker();
                      }
                    });
picker.build().setVisible(true);

This is what the implementation looks like :) For the complete React code, you can visit this link

https://i.sstatic.net/MVePo.png

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is it possible to hide and reveal specific form elements based on the selection of a checkbox?

Having issues with the code provided below, it's not working as expected. Can you help me figure out what I might be missing? HTML: <input id="id_code_col" type="checkbox" name="code_col"></input> SCRIPT: $(document).ready(function(){ ...

Utilizing React.js for displaying a collection of items

I have been working on a simple React program that involves displaying a button to the user. Upon clicking the button, an API call is made and the results are displayed in a list format. Although I have reached a point where I can successfully fetch and m ...

Unable to reach the array file

Having trouble accessing the elements of the file array const p_page = postP.new_pages; const p_page_o = postP.new_pages_order; const p_page_o_len = p_page_o.length; if (p_page_o_len > 0) { for (let i = 0; i < p_page_o_len; i++) { c ...

Tips on building an immersive interactive panoramic website

I have a vision for a website that will simulate being in a room, where users can explore the space with limited panoramic views - allowing them to look up/down 30 degrees and left/right 45 degrees. In addition, I would like to integrate interactive object ...

What is the best way to connect two web workers in HTML5?

I've been delving into the web workers documentation, but I'm coming up short on finding an API that facilitates direct communication between two web workers. The scenario I have is needing to establish a direct line of communication from worker1 ...

What is the best way to distribute javascript and html code across multiple elements on a webpage?

My webpage has a unique feature - two textboxes that trigger a bootstrap modal with a searchable treeview when clicked. The selected item from the treeview automatically populates the textbox. It's a flawless process! Recently, I decided to implement ...

Fetch information from MySQL, create a new row for each data entry

Currently, I am working on a project for my school that involves retrieving student works from a database. For the homepage of my project, I have set up 10 divs to hold the data returned from a query. The reason I preset these divs is because I only need ...

The attribute on the label fails to trigger any action on the linked input upon clicking, due to the binding of the id and for

My component is designed to display a checkbox and label, with inputs for id, name, label, and value. Here's the code: <div class="checkbox col-xs-12" *ngIf="id && name && label && value"> <input type="checkbox" ...

Facing issues with the forEach method in ReactJs when attempting to access data from an array

Struggling with a ReactJS issue, I've come across a problem with the HomePage Component where the forEach method isn't working as expected. I'm attempting to retrieve data from a defined array. Take a look at the code snippet below: import R ...

When there is no error, the catch block in Javascript promises is still being

I recently developed a function that calls an API as shown below. The goal was to display the message from setMessage on the frontend. However, I encountered a strange issue where the .catch block message briefly flashes in setMessage() even when there is ...

Tumblr jQuery Like (utilizing rel attribute for selection)

I developed a custom HTML5 theme using masonry and infinite-scroll, which has been functioning well. I am now trying to add reblog and like buttons to each post but I'm facing an issue with the like button not working. Here is the URL to the theme: ...

What are some strategies to reduce the frequency of API calls even when a webpage is reloaded?

Imagine I'm utilizing a complimentary API service that has a restriction of c calls per m minutes. My website consists of a simple HTML file with some JavaScript code like the one below: $(function () { //some code function getSomething() { ...

Instructions on submitting a form containing multiple select lists using the enter key

After researching various threads, I have come across solutions using the JS onkeypress function to trigger actions with input fields. However, in my case, I need to implement this functionality with a form that consists of multiple select lists instead of ...

Replace Original Image with Alternate Image if Image Error Occurs Using jQuery (Bootstrap File Input)

I am currently utilizing the Bootstrap File Input component for file uploads, and it's working splendidly. I have set up the initialPreviewConfig to display the existing image on the server. However, there are instances when there is no file available ...

What is the method for editing individual rows in a data table in Spring MVC when the edit button is clicked?

Every time I click on <a id="myBtn"><i class="fa fa-pencil" style="color:OliveDrab;"></i></a>, I only get a modal on the first row click, and it appears empty. I've searched through many internet resources, but none of them pro ...

The mistake in npm install is when the console logs a bug that is notorious for causing npm to malfunction

After reading this article, I successfully installed Node.JS version 9.4.0. $brew install node $node -v $v0.12.7 Next, I ran npm install -g grunt-cli for testing. H ...

Place the child atop the stacked blocks

I need the .square div to always remain at the top, creating a visual effect where it appears as if the following section with its own .square is sliding up and the .square halts precisely at the position of the previous section's square. The code sn ...

Requesting information from a NodeJs endpoint

I have a NodeJs application that requires calling an end-point (http:\localhost:9900\get\employee - asp.net web-api) to retrieve data. What are some options available for achieving this task? Is it possible to utilize promises in this scenar ...

Issue with Vue.js devtool not appearing in browser

Currently, I am integrating moment.js into a Vue component but I am facing an issue where certain changes are not being reflected in vue devtools. Here is an example of my code: export default { data() { return { moment: moment(), ...

Enhance the appearance of specific form inputs upon modification of ng-model within the textfield using AngularJS

After asking a similar question multiple times, I've realized that the specifics of my query were not clear enough. Let's say in my controller there is an object named "guy" of type person structured like this: {"ID" : "1234", "firstNam ...