url.mdx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. new Uppy()
  60. .use(Dashboard, { inline: true, target: '#dashboard' })
  61. .use(Url, { companionUrl: 'https://your-companion.com' });
  62. ```
  63. ### Use in Companion
  64. Companion supports this plugin out-of-the-box so integration is required on this
  65. side.
  66. ## API
  67. ### Options
  68. #### `id`
  69. A unique identifier for this plugin (`string`, default: `'Url'`).
  70. #### `title`
  71. Title / name shown in the UI, such as Dashboard tabs (`string`, default:
  72. `'Url'`).
  73. #### `target`
  74. DOM element, CSS selector, or plugin to place the drag and drop area into
  75. (`string`, `Element`, `Function`, or `UIPlugin`, default:
  76. [`Dashboard`](/docs/dashboard)).
  77. #### `companionUrl`
  78. URL to a [Companion](/docs/companion) instance (`string`, default: `null`).
  79. #### `companionHeaders`
  80. Custom headers that should be sent along to [Companion](/docs/companion) on
  81. every request (`Object`, default: `{}`).
  82. #### `companionAllowedHosts`
  83. The valid and authorised URL(s) from which OAuth responses should be accepted
  84. (`string` or `RegExp` or `Array`, default: `companionUrl`).
  85. This value can be a `string`, a `RegExp` pattern, or an `Array` of both. This is
  86. useful when you have your [Companion](/docs/companion) running on several hosts.
  87. Otherwise, the default value should do fine.
  88. #### `companionCookiesRule`
  89. This option correlates to the
  90. [RequestCredentials value](https://developer.mozilla.org/en-US/docs/Web/API/Request/credentials)
  91. (`string`, default: `'same-origin'`).
  92. This tells the plugin whether to send cookies to [Companion](/docs/companion).
  93. #### `locale`
  94. ```js
  95. export default {
  96. strings: {
  97. pluginNameUrl: 'Url',
  98. },
  99. };
  100. ```