unsplash.mdx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. ---
  2. slug: /unsplash
  3. ---
  4. import Tabs from '@theme/Tabs';
  5. import TabItem from '@theme/TabItem';
  6. import UppyCdnExample from '/src/components/UppyCdnExample';
  7. # Unsplash
  8. The `@uppy/unsplash` plugin lets users import files from their
  9. [Unsplash](https://unsplash.com) account.
  10. :::tip
  11. [Try out the live example](/examples) or take it for a spin in
  12. [StackBlitz](https://stackblitz.com/edit/vitejs-vite-zaqyaf?file=main.js).
  13. :::
  14. ## When should I use this?
  15. When you want to let users import files from their
  16. [Unsplash](https://unsplash.com) account.
  17. A [Companion](/docs/companion) instance is required for the Unsplash plugin to
  18. work. Companion handles authentication with Unsplash, downloads the files, and
  19. uploads them to the destination. This saves the user bandwidth, especially
  20. helpful if they are on a mobile connection.
  21. You can self-host Companion or get a hosted version with any
  22. [Transloadit plan](https://transloadit.com/pricing/).
  23. <Tabs>
  24. <TabItem value="npm" label="NPM" default>
  25. ```shell
  26. npm install @uppy/unsplash
  27. ```
  28. </TabItem>
  29. <TabItem value="yarn" label="Yarn">
  30. ```shell
  31. yarn add @uppy/unsplash
  32. ```
  33. </TabItem>
  34. <TabItem value="cdn" label="CDN">
  35. <UppyCdnExample>
  36. {`
  37. import { Uppy, Unsplash } from "{{UPPY_JS_URL}}"
  38. const uppy = new Uppy()
  39. uppy.use(Unsplash, {
  40. // Options
  41. })
  42. `}
  43. </UppyCdnExample>
  44. </TabItem>
  45. </Tabs>
  46. ## Use
  47. Using Unsplash requires setup in both Uppy and Companion.
  48. ### Use in Uppy
  49. ```js {10-13} showLineNumbers
  50. import Uppy from '@uppy/core';
  51. import Dashboard from '@uppy/dashboard';
  52. import Unsplash from '@uppy/unsplash';
  53. import '@uppy/core/dist/style.min.css';
  54. import '@uppy/dashboard/dist/style.min.css';
  55. new Uppy()
  56. .use(Dashboard, { inline: true, target: '#dashboard' })
  57. .use(Unsplash, {
  58. target: Dashboard,
  59. companionUrl: 'https://your-companion.com',
  60. });
  61. ```
  62. ### Use in Companion
  63. You can create a Unsplash App on the
  64. [Unsplash Developers site](https://unsplash.com/developers). You’ll be
  65. redirected to the app page, this page lists the app key and app secret.
  66. Configure the Unsplash key and secret. With the standalone Companion server,
  67. specify environment variables:
  68. ```shell
  69. export COMPANION_UNSPLASH_KEY="Unsplash API key"
  70. export COMPANION_UNSPLASH_SECRET="Unsplash API secret"
  71. ```
  72. When using the Companion Node.js API, configure these options:
  73. ```js
  74. companion.app({
  75. providerOptions: {
  76. unsplash: {
  77. key: 'Unsplash API key',
  78. secret: 'Unsplash API secret',
  79. },
  80. },
  81. });
  82. ```
  83. ## API
  84. ### Options
  85. #### `id`
  86. A unique identifier for this plugin (`string`, default: `'Unsplash'`).
  87. #### `title`
  88. Title / name shown in the UI, such as Dashboard tabs (`string`, default:
  89. `'Unsplash'`).
  90. #### `target`
  91. DOM element, CSS selector, or plugin to place the drag and drop area into
  92. (`string` or `Element`, default: `null`).
  93. #### `companionUrl`
  94. URL to a [Companion](/docs/companion) instance (`string`, default: `null`).
  95. #### `companionHeaders`
  96. Custom headers that should be sent along to [Companion](/docs/companion) on
  97. every request (`Object`, default: `{}`).
  98. #### `companionAllowedHosts`
  99. The valid and authorised URL(s) from which OAuth responses should be accepted
  100. (`string` or `RegExp` or `Array`, default: `companionUrl`).
  101. This value can be a `string`, a `RegExp` pattern, or an `Array` of both. This is
  102. useful when you have your [Companion](/docs/companion) running on several hosts.
  103. Otherwise, the default value should do fine.
  104. #### `companionCookiesRule`
  105. This option correlates to the
  106. [RequestCredentials value](https://developer.mozilla.org/en-US/docs/Web/API/Request/credentials)
  107. (`string`, default: `'same-origin'`).
  108. This tells the plugin whether to send cookies to [Companion](/docs/companion).
  109. #### `locale`
  110. ```js
  111. export default {
  112. strings: {
  113. pluginNameUnsplash: 'Unsplash',
  114. },
  115. };
  116. ```