rgd

react-google-drive-picker

React google drive picker api

Showing:

Popularity

Downloads/wk

181

GitHub Stars

9

Maintenance

Last Commit

23d ago

Contributors

3

Package

Dependencies

0

License

MIT

Type Definitions

Built-In

Tree-Shakeable

No?

Categories

Readme

React-google-drive-picker

Google drive picker

Description

Google drive picker custom hook.

Getting Started

Installing

With npm

npm i react-google-drive-picker

With yarn

yarn add react-google-drive-picker

Usage

import  { useEffect } from 'react';
import useDrivePicker from 'react-google-drive-picker'


function App() {
  const [openPicker, data, authResponse] = useDrivePicker();  
  // const customViewsArray = [new google.picker.DocsView()]; // custom view
  const handleOpenPicker = () => {
    openPicker({
      clientId: "xxxxxxxxxxxxxxxxx",
      developerKey: "xxxxxxxxxxxx",
      viewId: "DOCS",
      // token: token, // pass oauth token in case you already have one
      showUploadView: true,
      showUploadFolders: true,
      supportDrives: true,
      multiselect: true,
      // customViews: customViewsArray, // custom view
    })
  }

  useEffect(() => {
    // do anything with the selected/uploaded files
    if(data){
      data.docs.map(i => console.log(i.name))
    }
  }, [data])

  
  return (
    <div>
        <button onClick={() => handleOpenPicker()}>Open Picker</button>
    </div>
  );
}

export default App;

Picker configuration props

Picker Props

paramsvaluedefault valuedescription
clientIdstringREQUIREDGoogle client id
developerKeystringREQUIREDGoogle developer key
disableDefaultViewbooleanfalsedisables default view
viewIdstringDOCSViewIdOptions
viewMimeTypesstringoptionalComma separated mimetypes. Use this in place of viewId if you need to filter multiple type of files. list: https://developers.google.com/drive/api/v3/mime-types.
setIncludeFoldersbooleanfalseShow folders in the view items.
setSelectFolderEnabledbooleanfalseAllows the user to select a folder in Google Drive.
tokenstringoptionalaccess_token to skip auth part
multiselectbooleanfalseEnable picker multiselect
supportDrivesbooleanfalseSupport shared drives
showUploadViewbooleanfalseEnable upload view
showUploadFoldersbooleanfalseEnable folder selection(upload)
setParentFolderstringdisabledDrive folder id to upload
customViewsViewClass[]optionalArray of custom views you want to add to the picker
customScopesstring[]['https://www.googleapis.com/auth/drive.readonly']Array of custom scopes you want to add to the picker
localestringenList of supported locales https://developers.google.com/picker/docs#i18n

viewId options

optiondescription
DOCSAll Google Drive document types.
DOCS_IMAGESGoogle Drive photos.
DOCS_IMAGES_AND_VIDEOSGoogle Drive photos and videos.
DOCS_VIDEOSGoogle Drive videos.
DOCUMENTSGoogle Drive Documents.
FOLDERSGoogle Drive Folders.
DRAWINGSGoogle Drive Drawings.
FORMSGoogle Drive Forms.
PDFSPDF files stored in Google Drive.
SPREADSHEETSGoogle Drive Spreadsheets.

Author

@Jose medina

Acknowledgments

Inspiration, code snippets

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100