()
| 38 | } |
| 39 | |
| 40 | function createTransloaditUppy() { |
| 41 | const uppy = new Uppy({ |
| 42 | restrictions: { |
| 43 | maxFileSize: 100 * 1024 * 1024, // 100MB |
| 44 | maxNumberOfFiles: 10, |
| 45 | }, |
| 46 | }) |
| 47 | |
| 48 | uppy.use(Transloadit, { |
| 49 | async assemblyOptions() { |
| 50 | // You can send meta data along for use in your template. |
| 51 | // https://transloadit.com/docs/topics/assembly-instructions/#form-fields-in-instructions |
| 52 | const { meta } = uppy.getState() |
| 53 | const body = JSON.stringify({ |
| 54 | customValue: meta.customValue || 'react-router-uppy-example', |
| 55 | }) |
| 56 | const res = await fetch('/api/transloadit-params', { |
| 57 | method: 'POST', |
| 58 | headers: { 'Content-Type': 'application/json' }, |
| 59 | body, |
| 60 | }) |
| 61 | if (!res.ok) { |
| 62 | const errorData = await res.json().catch(() => ({})) |
| 63 | if (errorData.details) { |
| 64 | throw new Error(errorData.details) |
| 65 | } |
| 66 | throw new Error(`Failed to get Transloadit params: ${res.statusText}`) |
| 67 | } |
| 68 | return res.json() |
| 69 | }, |
| 70 | }) |
| 71 | |
| 72 | return uppy |
| 73 | } |
| 74 | |
| 75 | export default function Index() { |
| 76 | const [tusUppy] = useState(createTusUppy) |
nothing calls this directly
no test coverage detected
searching dependent graphs…