diff --git a/404.html b/404.html index 021938bb7..07657a026 100644 --- a/404.html +++ b/404.html @@ -13,7 +13,7 @@ - +
diff --git a/assets/js/427b2579.a8a4ec71.js b/assets/js/427b2579.a8a4ec71.js new file mode 100644 index 000000000..f3d31a3bf --- /dev/null +++ b/assets/js/427b2579.a8a4ec71.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkuppy_io=self.webpackChunkuppy_io||[]).push([[7873],{41649:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>a,default:()=>d,frontMatter:()=>s,metadata:()=>i,toc:()=>u});var r=n(74848),o=n(28453);const s={slug:"/reactrouter"},a="React Router",i={id:"framework-integrations/react-router",title:"React Router",description:"Integration guide for the React components for the Uppy UI plugins and",source:"@site/docs/framework-integrations/react-router.mdx",sourceDirName:"framework-integrations",slug:"/reactrouter",permalink:"/docs/reactrouter",draft:!1,unlisted:!1,editUrl:"https://github.com/transloadit/uppy.io/blob/main/docs/framework-integrations/react-router.mdx",tags:[],version:"current",frontMatter:{slug:"/reactrouter"},sidebar:"tutorialSidebar",previous:{title:"Next.js",permalink:"/docs/nextjs"},next:{title:"React",permalink:"/docs/react"}},c={},u=[{value:"Install",id:"install",level:2},{value:"Tus",id:"tus",level:2},{value:"Transloadit",id:"transloadit",level:2},{value:"HTTP uploads to your backend",id:"http-uploads-to-your-backend",level:2},{value:"Next steps",id:"next-steps",level:2}];function p(e){const t={a:"a",admonition:"admonition",code:"code",h1:"h1",h2:"h2",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,o.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(t.h1,{id:"react-router",children:"React Router"}),"\n",(0,r.jsxs)(t.p,{children:["Integration guide for the ",(0,r.jsx)(t.a,{href:"https://facebook.github.io/react",children:"React"})," components for the Uppy UI plugins and\nhooks."]}),"\n",(0,r.jsx)(t.admonition,{type:"tip",children:(0,r.jsxs)(t.p,{children:["Uppy also has hooks and more React examples in the ",(0,r.jsx)(t.a,{href:"/docs/react",children:"React docs"}),"."]})}),"\n",(0,r.jsx)(t.h2,{id:"install",children:"Install"}),"\n",(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-shell",children:"npm install @uppy/core @uppy/dashboard @uppy/react\n"})}),"\n",(0,r.jsx)(t.h2,{id:"tus",children:"Tus"}),"\n",(0,r.jsxs)(t.p,{children:[(0,r.jsx)(t.a,{href:"https://tus.io/",children:"Tus"})," is an open protocol for resumable uploads built on HTTP. This means\naccidentally closing your tab or losing connection lets you continue, for\ninstance, your 10GB upload instead of starting all over."]}),"\n",(0,r.jsxs)(t.p,{children:["Tus supports any language, any platform, and any network. It requires a client\nand server integration to work. We will be using ",(0,r.jsx)(t.a,{href:"https://github.com/tus/tus-node-server",children:"tus Node.js"}),"."]}),"\n",(0,r.jsxs)(t.p,{children:["Checkout the ",(0,r.jsxs)(t.a,{href:"/docs/tus",children:[(0,r.jsx)(t.code,{children:"@uppy/tus"})," docs"]})," for more information."]}),"\n",(0,r.jsx)(t.p,{children:"Create a route where you want to handle uploads:"}),"\n",(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-tsx",children:"import { useEffect, useState } from 'react';\nimport Uppy from '@uppy/core';\nimport Dashboard from '@uppy/react/lib/Dashboard';\nimport Tus from '@uppy/tus';\n\nimport '@uppy/core/dist/style.min.css';\nimport '@uppy/dashboard/dist/style.min.css';\n\nfunction createUppy() {\n\treturn new Uppy().use(Tus, { endpoint: '/api/upload' });\n}\n\nexport default function UppyDashboard() {\n\t// Important: use an initializer function to prevent the state from recreating.\n\tconst [uppy] = useState(createUppy);\n\n\treturnimport { data } from 'react-router';
import type { ActionFunction } from 'rea';
import crypto from 'crypto';
function utcDateString(ms: number): string {
return new Date(ms)
.toISOString()
.replace(/-/g, '/')
.replace(/T/, ' ')
.replace(/\.\d+Z$/, '+00:00');
}
export const action: ActionFunction = async ({ request }) => {
// expire 1 hour from now (this must be milliseconds)
const expires = utcDateString(Date.now() + 1 * 60 * 60 * 1000);
const authKey = process.env.TRANSLOADIT_KEY;
const authSecret = process.env.TRANSLOADIT_SECRET;
const templateId = process.env.TRANSLOADIT_TEMPLATE_ID;
if (!authKey || !authSecret || !templateId) {
throw data({ error: 'Missing Transloadit credentials' }, { status: 500 });
}
const body = await request.json();
const params = JSON.stringify({
auth: {
key: authKey,
expires,
},
template_id: templateId,
fields: {
// You can use this in your template.
customValue: body.customValue,
},
// your other params like notify_url, etc.
});
const signatureBytes = crypto
.createHmac('sha384', authSecret)
.update(Buffer.from(params, 'utf-8'));
// The final signature needs the hash name in front, so
// the hashing algorithm can be updated in a backwards-compatible
// way when old algorithms become insecure.
const signature = `sha384:${signatureBytes.digest('hex')}`;
return data({ expires, signature, params });
};
import { data } from 'react-router';
import type { ActionFunction } from 'react-router';
import crypto from 'crypto';
function utcDateString(ms: number): string {
return new Date(ms)
.toISOString()
.replace(/-/g, '/')
.replace(/T/, ' ')
.replace(/\.\d+Z$/, '+00:00');
}
export const action: ActionFunction = async ({ request }) => {
// expire 1 hour from now (this must be milliseconds)
const expires = utcDateString(Date.now() + 1 * 60 * 60 * 1000);
const authKey = process.env.TRANSLOADIT_KEY;
const authSecret = process.env.TRANSLOADIT_SECRET;
const templateId = process.env.TRANSLOADIT_TEMPLATE_ID;
if (!authKey || !authSecret || !templateId) {
throw data({ error: 'Missing Transloadit credentials' }, { status: 500 });
}
const body = await request.json();
const params = JSON.stringify({
auth: {
key: authKey,
expires,
},
template_id: templateId,
fields: {
// You can use this in your template.
customValue: body.customValue,
},
// your other params like notify_url, etc.
});
const signatureBytes = crypto
.createHmac('sha384', authSecret)
.update(Buffer.from(params, 'utf-8'));
// The final signature needs the hash name in front, so
// the hashing algorithm can be updated in a backwards-compatible
// way when old algorithms become insecure.
const signature = `sha384:${signatureBytes.digest('hex')}`;
return data({ expires, signature, params });
};
On the client we want to fetch the signature and params from the server. You may
want to send values from React state along to your endpoint, for instance to add
fields
which you
diff --git a/docs/remote-sources/index.html b/docs/remote-sources/index.html
index a3ecfd97f..a15e14f62 100644
--- a/docs/remote-sources/index.html
+++ b/docs/remote-sources/index.html
@@ -13,7 +13,7 @@
-
+