slug |
---|
/google-drive |
import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem';
import UppyCdnExample from '/src/components/UppyCdnExample';
The @uppy/google-drive
plugin lets users import files from their
Google Drive account.
:::tip
Try out the live example or take it for a spin in StackBlitz.
:::
When you want to let users import files from their Google Drive account.
A Companion instance is required for the Google Drive plugin to work. Companion handles authentication with Google Drive, downloads the files, and uploads them to the destination. This saves the user bandwidth, especially helpful if they are on a mobile connection.
You can self-host Companion or get a hosted version with any Transloadit plan.
npm install @uppy/google-drive
yarn add @uppy/google-drive
Using Google Drive requires setup in both Uppy and Companion.
import Uppy from '@uppy/core';
import Dashboard from '@uppy/dashboard';
import GoogleDrive from '@uppy/google-drive';
import '@uppy/core/dist/style.min.css';
import '@uppy/dashboard/dist/style.min.css';
new Uppy()
.use(Dashboard, { inline: true, target: '#dashboard' })
.use(GoogleDrive, { companionUrl: 'https://your-companion.com' });
To sign up for API keys, go to the Google Developer Console.
Create a project for your app if you don’t have one yet.
- On the project’s dashboard, enable the Google Drive API.
- Set up OAuth authorization.
- Under scopes, add the
https://www.googleapis.com/auth/drive.readonly
Drive API scope. - Due to this being a sensitive scope, your app must complete Google’s OAuth app verification before being granted access. See OAuth App Verification Help Center for more information.
- Under scopes, add the
The app page has a "Redirect URIs"
field. Here, add:
https://$YOUR_COMPANION_HOST_NAME/drive/redirect
If you are using Transloadit hosted Companion:
https://api2.transloadit.com/companion/drive/redirect
Google will give you an OAuth client ID and client secret.
Configure the Google Drive key and secret in Companion. With the standalone Companion server, specify environment variables:
export COMPANION_GOOGLE_KEY="Google Drive OAuth client ID"
export COMPANION_GOOGLE_SECRET="Google Drive OAuth client secret"
When using the Companion Node.js API, configure these options:
companion.app({
providerOptions: {
drive: {
key: 'Google Drive OAuth client ID',
secret: 'Google Drive OAuth client secret',
},
},
});
A unique identifier for this plugin (string
, default: 'GoogleDrive'
).
Title / name shown in the UI, such as Dashboard tabs (string
, default:
'GoogleDrive'
).
DOM element, CSS selector, or plugin to place the drag and drop area into
(string
, Element
, Function
, or UIPlugin
, default:
Dashboard
).
URL to a Companion instance (string
, default: null
).
Custom headers that should be sent along to Companion on
every request (Object
, default: {}
).
The valid and authorised URL(s) from which OAuth responses should be accepted
(string
or RegExp
or Array
, default: companionUrl
).
This value can be a string
, a RegExp
pattern, or an Array
of both. This is
useful when you have your Companion running on several hosts.
Otherwise, the default value should do fine.
This option correlates to the
RequestCredentials value
(string
, default: 'same-origin'
).
This tells the plugin whether to send cookies to Companion.
export default {
strings: {
pluginNameGoogleDrive: 'GoogleDrive',
},
};