url.mdx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. ---
  2. slug: /url
  3. ---
  4. import Tabs from '@theme/Tabs';
  5. import TabItem from '@theme/TabItem';
  6. import UppyCdnExample from '/src/components/UppyCdnExample';
  7. # Import from URL
  8. The `@uppy/url` plugin allows users to import files from the internet. Paste any
  9. URL and it will be added!
  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 any URL.
  16. A [Companion](/docs/companion) instance is required for the URL plugin to work.
  17. This saves the user bandwidth, especially helpful if they are on a mobile
  18. connection.
  19. You can self-host Companion or get a hosted version with any
  20. [Transloadit plan](https://transloadit.com/pricing/).
  21. :::note
  22. Companion has
  23. [Server Side Request Forgery](https://owasp.org/www-community/attacks/Server_Side_Request_Forgery)
  24. (SSRF) protections built-in so you don’t have to worry about the security
  25. implications of arbitrary URLs.
  26. :::
  27. <Tabs>
  28. <TabItem value="npm" label="NPM" default>
  29. ```shell
  30. npm install @uppy/url
  31. ```
  32. </TabItem>
  33. <TabItem value="yarn" label="Yarn">
  34. ```shell
  35. yarn add @uppy/url
  36. ```
  37. </TabItem>
  38. <TabItem value="cdn" label="CDN">
  39. <UppyCdnExample>
  40. {`
  41. import { Uppy, Url } from "{{UPPY_JS_URL}}"
  42. const uppy = new Uppy()
  43. uppy.use(Url, {
  44. // Options
  45. })
  46. `}
  47. </UppyCdnExample>
  48. </TabItem>
  49. </Tabs>
  50. ## Use
  51. Using `@uppy/url` only requires setup in Uppy.
  52. ### Use in Uppy
  53. ```js {10-13} showLineNumbers
  54. import Uppy from '@uppy/core';
  55. import Dashboard from '@uppy/dashboard';
  56. import Url from '@uppy/url';
  57. import '@uppy/core/dist/style.min.css';
  58. import '@uppy/dashboard/dist/style.min.css';
  59. import "@uppy/url/dist/style.min.css";
  60. new Uppy()
  61. .use(Dashboard, { inline: true, target: '#dashboard' })
  62. .use(Url, { companionUrl: 'https://your-companion.com' });
  63. ```
  64. ### Use in Companion
  65. Companion supports this plugin out-of-the-box, however it must be enabled in
  66. Companion with the `enableUrlEndpoint` / `COMPANION_ENABLE_URL_ENDPOINT` option.
  67. ## API
  68. ### Options
  69. #### `id`
  70. A unique identifier for this plugin (`string`, default: `'Url'`).
  71. #### `title`
  72. Title / name shown in the UI, such as Dashboard tabs (`string`, default:
  73. `'Url'`).
  74. #### `target`
  75. DOM element, CSS selector, or plugin to place the drag and drop area into
  76. (`string`, `Element`, `Function`, or `UIPlugin`, default:
  77. [`Dashboard`](/docs/dashboard)).
  78. #### `companionUrl`
  79. URL to a [Companion](/docs/companion) instance (`string`, default: `null`).
  80. #### `companionHeaders`
  81. Custom headers that should be sent along to [Companion](/docs/companion) on
  82. every request (`Object`, default: `{}`).
  83. #### `companionAllowedHosts`
  84. The valid and authorised URL(s) from which OAuth responses should be accepted
  85. (`string` or `RegExp` or `Array`, default: `companionUrl`).
  86. This value can be a `string`, a `RegExp` pattern, or an `Array` of both. This is
  87. useful when you have your [Companion](/docs/companion) running on several hosts.
  88. Otherwise, the default value should do fine.
  89. #### `companionCookiesRule`
  90. This option correlates to the
  91. [RequestCredentials value](https://developer.mozilla.org/en-US/docs/Web/API/Request/credentials)
  92. (`string`, default: `'same-origin'`).
  93. This tells the plugin whether to send cookies to [Companion](/docs/companion).
  94. #### `locale`
  95. ```js
  96. export default {
  97. strings: {
  98. pluginNameUrl: 'Url',
  99. },
  100. };
  101. ```