Google Photos Picker
The @uppy/google-photos-picker
plugin lets users import files from their
Google Drive account using the new
Picker API.
A Companion instance is required for the Google Drive Picker plugin to work. Companion downloads the files from Google Drive, 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.
See also Google Drive Picker.
When should I use this?
When you want to let users import files from their Google Photos account.
You should use this plugin over our other Google Photos plugin if you want to avoid using a restricted API scope, which requires CASA Tier 2 compliance.
The downside of using the Picker UI made by Google is less controls, inability to select folders, downloading an additional bundle, and a less consistent user experience.
- NPM
- Yarn
- CDN
npm install @uppy/google-photos-picker
yarn add @uppy/google-photos-picker
The bundle consists of most Uppy plugins, so this method is not recommended for production, as your users will have to download all plugins when you are likely using only a few.
It can be useful to speed up your development environment, so don't hesitate to use it to get you started.
<!-- 1. Add CSS to `<head>` -->
<link href="https://releases.transloadit.com/uppy/v4.8.0/uppy.min.css" rel="stylesheet">
<!-- 2. Initialize -->
<div id="uppy"></div>
<script type="module">
import { Uppy, GooglePhotosPicker } from "https://releases.transloadit.com/uppy/v4.8.0/uppy.min.mjs"
const uppy = new Uppy()
uppy.use(GooglePhotosPicker, {
// Options
})
</script>
Use
Using Google Photos Picker requires setup in both Uppy and Companion.
Initial setup
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 Photos Picker API.
- Create an OAuth 2.0 Client ID of type Web application with the correct Authorized JavaScript origins.
Use in Uppy
import Uppy from '@uppy/core';
import Dashboard from '@uppy/dashboard';
import GooglePhotosPicker from '@uppy/google-photos-picker';
import '@uppy/core/dist/style.min.css';
import '@uppy/dashboard/dist/style.min.css';
new Uppy()
.use(Dashboard, { inline: true, target: '#dashboard' })
.use(GooglePhotosPicker, {
companionUrl: 'https://your-companion.com',
clientId: 'From Google Developer Console',
});
Use with Transloadit
import { COMPANION_URL, COMPANION_ALLOWED_HOSTS } from '@uppy/transloadit';
import GooglePhotosPicker from '@uppy/google-photos-picker';
uppy.use(GooglePhotosPicker, {
companionUrl: COMPANION_URL,
companionAllowedHosts: COMPANION_ALLOWED_HOSTS,
clientId: 'From Google Developer Console',
});
Use in Companion
Companion is used to download/upload the picked files. Companion supports this
plugin out-of-the-box, however it must be enabled in Companion with the
enableGooglePickerEndpoint
/ COMPANION_ENABLE_GOOGLE_PICKER_ENDPOINT
option.
For this plugin, all credentials are public (non-secret) and provided in the
frontend.
API
Options
id
A unique identifier for this plugin (string
, default is a unique ID for each
plugin).
title
Title / name shown in the UI, such as Dashboard tabs (string
, default is the
name of the plugin).
target
DOM element, CSS selector, or plugin to place the drag and drop area into
(string
, Element
, Function
, or UIPlugin
, default:
Dashboard
).
companionUrl
URL to a Companion instance (string
, default: null
).
companionHeaders
Custom headers that should be sent along to Companion on
every request (Object
, default: {}
).
companionAllowedHosts
The valid and authorised URL(s) from which OAuth responses should be accepted
(string
or RegExp
or Array
). This option is useful when you have your
Companion running on several hosts. Otherwise, the default
value should do fine, which uses the origin of companionUrl
.
This value can be a string
, a RegExp
pattern, or an Array
of these.
Strings are evaluated as regular expressions too and will be wrapped in a RegExp
like so:
new RegExp(`^${value}$`);
Important: You must escape regex characters like .
, or you might open your
app up to security vulnerabilities.
- Example correct strings
'^(?:.*\\.)?example\.com$'
matchesexample.com
and all of its subdomains.'https://example\.com'
matcheshttps://example.com
only.
- Example vulnerability:
'https://www.example.com'
would allow an attacker with the domainwwwxexample.com
to forge and inject a fraudulent token into Uppy.
companionCookiesRule
This option correlates to the
RequestCredentials value
(string
, default: 'same-origin'
).
This tells the plugin whether to send cookies to Companion.
locale
An object with strings
property containing additional i18n strings. The key is
the i18n key and the value is the English string.
Example:
{
strings: {
someKey: 'Some English string',
},
}
storage
A custom storage to be used for the plugin’s persistent data. Type AsyncStore
,
default is LocalStorage
.
clientId
The client ID from the Initial setup (string
).