main.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. const transloadit = require('@uppy/transloadit-preset')
  2. /**
  3. * transloadit.form
  4. */
  5. const formUppy = transloadit.form('#test-form', {
  6. debug: true,
  7. fields: ['message'],
  8. restrictions: {
  9. allowedFileTypes: ['.png']
  10. },
  11. waitForEncoding: true,
  12. params: {
  13. auth: { key: '05a61ed019fe11e783fdbd1f56c73eb0' },
  14. template_id: 'be001500a56011e889f9cddd88df842c'
  15. },
  16. modal: true,
  17. progressBar: '#test-form .progress'
  18. })
  19. formUppy.on('error', (err) => {
  20. document.querySelector('#test-form .error')
  21. .textContent = err.message
  22. })
  23. formUppy.on('upload-error', (file, err) => {
  24. document.querySelector('#test-form .error')
  25. .textContent = err.message
  26. })
  27. window.formUppy = formUppy
  28. const formUppyWithDashboard = transloadit.form('#dashboard-form', {
  29. debug: true,
  30. fields: ['message'],
  31. restrictions: {
  32. allowedFileTypes: ['.png']
  33. },
  34. waitForEncoding: true,
  35. params: {
  36. auth: { key: '05a61ed019fe11e783fdbd1f56c73eb0' },
  37. template_id: 'be001500a56011e889f9cddd88df842c'
  38. },
  39. dashboard: '#dashboard-form .dashboard'
  40. })
  41. window.formUppyWithDashboard = formUppyWithDashboard
  42. /**
  43. * transloadit.modal
  44. */
  45. function openModal () {
  46. transloadit.pick({
  47. restrictions: {
  48. allowedFileTypes: ['.png']
  49. },
  50. waitForEncoding: true,
  51. params: {
  52. auth: { key: '05a61ed019fe11e783fdbd1f56c73eb0' },
  53. template_id: 'be001500a56011e889f9cddd88df842c'
  54. },
  55. providers: [
  56. 'webcam'
  57. ]
  58. // if providers need custom config
  59. // webcam: {
  60. // option: 'whatever'
  61. // }
  62. }).then(console.log, console.error)
  63. }
  64. window.openModal = openModal
  65. /**
  66. * transloadit.upload
  67. */
  68. window.doUpload = (event) => {
  69. transloadit.upload(event.target.files, {
  70. waitForEncoding: true,
  71. params: {
  72. auth: { key: '05a61ed019fe11e783fdbd1f56c73eb0' },
  73. template_id: 'be001500a56011e889f9cddd88df842c'
  74. }
  75. }).then(console.log, console.error)
  76. }