index.ejs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. ---
  2. title: Transloadit
  3. layout: example
  4. type: examples
  5. order: 1
  6. category: 'File Processing'
  7. ---
  8. {% blockquote %}
  9. Transloadit is the inventor of <a href="https://tus.io" rel="noreferrer noopener" target="_blank">tus.io</a> and Uppy. Besides a robust encoding platform, Transloadit offers hosted versions of tusd and Companion. This means you can enjoy video encoding, watermarking, face detection, resumable file uploads, fetching from Instagram, etc — all without running a single server yourself.
  10. This example demonstrates how to unlock Transloadit’s features within Uppy.
  11. {% endblockquote %}
  12. <p>
  13. In this particular example we take your images (from Instagram), resize them to 250px and add the copyright caption text: <code>© 2018 Transloadit.com</code> at the bottom right corner.
  14. </p>
  15. <p>
  16. For this demo to work you'll need a (free) Transloadit account. To get one:
  17. </p>
  18. <ol>
  19. <li>
  20. <a href="https://transloadit.com/signup/" rel="noreferrer noopener" target="_blank">Claim your account</a>. It will activate instantly. You can also signup via GitHub to avoid password hassle.
  21. </li>
  22. <li>
  23. Copy the API Key that you can find on
  24. <a href="https://transloadit.com/accounts/credentials" rel="noreferrer noopener" target="_blank">this page</a> and paste it below.
  25. </li>
  26. <li>
  27. Happy encoding &amp; fetching from Instagram :)
  28. </li>
  29. </ol>
  30. <p>
  31. <label for="transloadit-api-key"
  32. style="display: block; font-size: 13px; text-transform: uppercase; font-weight: bold;">
  33. Transloadit API Key:</label>
  34. <input type="text"
  35. style="font-size: 15px; width: 300px; max-width: 100%; border: 0; border-bottom: 1px solid black; padding: 6px 8px; margin-bottom: 20px;"
  36. id="transloadit-api-key"
  37. placeholder="Your Transloadit API Key">
  38. </p>
  39. <link rel="stylesheet" href="app.css">
  40. <% include app.html %>
  41. <hr />
  42. <p id="console-wrapper">Console output (latest logs are at the top):
  43. <br />
  44. </p>
  45. <script src="app.js"></script>
  46. <script>
  47. var apiKeyEl = document.getElementById('transloadit-api-key')
  48. var storedApiKey = localStorage.getItem('uppyTransloaditApiKey')
  49. if (storedApiKey) {
  50. apiKeyEl.value = storedApiKey
  51. window.TRANSLOADIT_API_KEY = storedApiKey
  52. initUppy()
  53. }
  54. function handleInputChange (ev) {
  55. var enteredApiKey = ev.target.value
  56. window.TRANSLOADIT_API_KEY = enteredApiKey
  57. localStorage.setItem('uppyTransloaditApiKey', enteredApiKey)
  58. initUppy()
  59. }
  60. apiKeyEl.addEventListener('change', handleInputChange)
  61. apiKeyEl.addEventListener('keyup', handleInputChange)
  62. apiKeyEl.addEventListener('paste', handleInputChange)
  63. </script>
  64. <hr />
  65. <p>On this page we're using the following JavaScript:</p>
  66. {% codeblock lang:js %}
  67. const Uppy = require('@uppy/core')
  68. const Dashboard = require('@uppy/transloadit')
  69. const Webcam = require('@uppy/webcam')
  70. const Transloadit = require('@uppy/transloadit')
  71. const Instagram = require('@uppy/instagram')
  72. const uppy = Uppy({
  73. debug: true,
  74. autoProceed: false,
  75. restrictions: {
  76. maxFileSize: 1024 * 1024 * 1024,
  77. maxNumberOfFiles: 2,
  78. minNumberOfFiles: 1,
  79. allowedFileTypes: ['image/*']
  80. }
  81. })
  82. uppy
  83. .use(Transloadit, {
  84. params: {
  85. auth: {
  86. key: YOUR_TRANSLOADIT_API_KEY
  87. },
  88. // It's more secure to use a template_id and enable
  89. // Signature Authentication
  90. steps: {
  91. resize: {
  92. robot: '/image/resize',
  93. width: 250,
  94. height: 250,
  95. resize_strategy: 'fit',
  96. text: [
  97. {
  98. text: '© 2018 Transloadit.com',
  99. size: 12,
  100. font: 'Ubuntu',
  101. color: '#eeeeee',
  102. valign: 'bottom',
  103. align: 'right',
  104. x_offset: 16,
  105. y_offset: -10
  106. }
  107. ]
  108. }
  109. }
  110. },
  111. waitForEncoding: true
  112. })
  113. .use(Instagram, { target: Dashboard, companionUrl: 'https://api2.transloadit.com/companion', companionAllowedHosts: /\.transloadit\.com$/ })
  114. .use(Dashboard, {
  115. inline: true,
  116. maxHeight: 400,
  117. target: '#uppy-dashboard-container',
  118. note: 'Images and video only, 1–2 files, up to 1 MB'
  119. })
  120. .use(Webcam, { target: Dashboard })
  121. .on('transloadit:result', (stepName, result) => {
  122. const file = uppy.getFile(result.localId)
  123. var resultContainer = document.createElement('div')
  124. resultContainer.innerHTML = `
  125. <div>
  126. <h3>Name: ${file.name}</h3>
  127. <img src="${result.ssl_url}" /> <br />
  128. <a href="${result.ssl_url}">View</a>
  129. </div>
  130. `
  131. document
  132. .getElementById('uppy-transloadit-result')
  133. .appendChild(resultContainer)
  134. })
  135. {% endcodeblock %}