main.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. const transloadit = require('@uppy/transloadit-preset')
  2. transloadit.modal('body', {
  3. restrictions: {
  4. allowedFileTypes: ['.png']
  5. },
  6. waitForEncoding: true,
  7. params: {
  8. auth: { key: '05a61ed019fe11e783fdbd1f56c73eb0' },
  9. template_id: 'be001500a56011e889f9cddd88df842c'
  10. },
  11. providers: [
  12. 'webcam'
  13. ]
  14. // if providers need custom config
  15. // webcam: {
  16. // option: 'whatever'
  17. // }
  18. }).then(console.log, console.error)
  19. window.formUppy = transloadit.form('#test-form', {
  20. debug: true,
  21. restrictions: {
  22. allowedFileTypes: ['.png']
  23. },
  24. waitForEncoding: true,
  25. params: {
  26. auth: { key: '05a61ed019fe11e783fdbd1f56c73eb0' },
  27. template_id: 'be001500a56011e889f9cddd88df842c'
  28. }
  29. })
  30. const input = document.createElement('input')
  31. input.setAttribute('type', 'file')
  32. input.setAttribute('multiple', 'multiple')
  33. const p = document.createElement('p')
  34. p.append(
  35. document.createTextNode('An <input type=file> backed by `transloadit.upload`:'),
  36. input
  37. )
  38. input.addEventListener('change', () => {
  39. transloadit.upload(input.files, {
  40. waitForEncoding: true,
  41. params: {
  42. auth: { key: '05a61ed019fe11e783fdbd1f56c73eb0' },
  43. template_id: 'be001500a56011e889f9cddd88df842c'
  44. }
  45. }).then(console.log, console.error)
  46. })
  47. document.querySelector('main').append(p)