import { docsMetadata } from "@/lib/utils"; export const metadata = docsMetadata({ title: "uploadthing/client", description: "The UploadThing Client module provides utilities for working with files in your application and communicating with your backend file router.", category: "API Reference", }); # uploadthing/client The UploadThing Client module provides utilities for working files in your application and communicating with your backend file router. ## `uploadFiles` {{ tag: 'function', since: '5.0' }} This function is used to perform [client side uploads](/uploading-files#client-side-uploads) by requesting presigned URLs from your backend file router, and then uploading the files to the storage provider. Use the `genUploader` factory function to generate a typed function that matches the signature of your file router, which will allow autocompletion and type checking on endpoint, route input and callback data types. ```ts import { genUploader } from "uploadthing/client"; import type { UploadRouter } from "~/server/uploadthing"; export const { uploadFiles } = genUploader(); const response = await uploadFiles("routeEndpoint", { files: [], }); ``` ### Parameters The first parameter is the route endpoint to upload to, and the second parameter is an options object: The endpoint arg may be a string literal or a callback function: ```ts await uploadFiles((routeRegistry) => routeRegistry.routeEndpoint, { ... }) ``` Using a callback function allows `Go to Definition` on `routeEndpoint` to take you straight to your backend file route definition, which is not possible when using a string literal parameter. An array of files to upload. Input JSON data matching your validator set on the [FileRoute](/file-routes#input) to send with the request. Headers to be sent along the request to request the presigned URLs. Useful for authentication outside full-stack framework setups. An abort signal to abort the upload. Callback function called after the presigned URLs have been retrieved, just before the file is uploaded. Called once per file. Callback function that gets continuously called as the file is uploaded to the storage provider. ### Returns The function returns a `Promise` that resolves to an array of objects: The name of the file. The size of the file in bytes. The type of the file. The file key of the file. The url of the file. The custom id of the file, if provided on upload. The data returned from the `onUploadComplete` callback on the file route. This will be `null` if `RouteOptions.awaitServerData` isn't enabled. ## `createUpload` {{ tag: 'function', since: '7.0' }} Create a resumable upload. Resumable uploads allows you to start an upload, pause it, and then resume it at a later time. As long as the presigned URL is valid, you can continue the upload from where it left off. As for `uploadFiles`, use the `genUploader` factory function to generate a typed function that matches the signature of your file router, which will allow autocompletion and type checking on endpoint, route input and callback data types. Due to difficulties integrating with React Native's `Blob` implementation, resumable uploads are currently not supported on React Native. ```ts import { genUploader } from "uploadthing/client"; import type { UploadRouter } from "~/server/uploadthing"; export const { createUpload } = genUploader(); // Create the upload. The files will start uploading immediately. const { pauseUpload, resumeUpload, done } = createUpload("routeEndpoint", { files: [], }); // Pause the upload of a file pauseUpload(file); // Resume the upload of a file resumeUpload(file); // Await the completion of all files const files = await done(); ``` ### Parameters The first parameter is the route endpoint to upload to, and the second parameter is an options object: An array of files to upload. Input JSON data matching your validator set on the [FileRoute](/file-routes#input) to send with the request. Headers to be sent along the request to request the presigned URLs. Useful for authentication outside full-stack framework setups. Callback function that gets continuously called as the file is uploaded to the storage provider. ### Returns Pause the upload of a file. If no file is provided, all files will be paused. Resume the upload of a file. If no file is provided, all files will be resumed. Await the completion of the upload of a file. If no file is provided, all files will be awaited. The returned object is the same as the one returned by `uploadFiles`. If a file is provided, the function returns an object, else it returns an array. ## `generateClientDropzoneAccept` {{ tag: 'function', since: '6.0' }} Generate an accepted object that can be passed to the `accept` prop of a `useDropzone` hook or `Dropzone` component. ### Parameters The route config to generate the accept props for. ### Returns `object` ## `generateMimeTypes` {{ tag: 'function', since: '6.0' }} Generate an array of accepted mime types given a route config. ### Parameters The route config to generate the accept props for. ### Returns `string[]` ## `generatePermittedFileTypes` {{ tag: 'function', since: '6.0' }} Utility function to generate accept props for a `` element. ### Parameters The route config to generate the accept props for. ### Returns The route config to generate the accept props for. Whether the accept props should be for multiple files. ## `isValidSize` {{ tag: 'function', since: '6.11' }} This function is used to validate that a file is of a valid size given a route config. ### Parameters The size of the file to validate. The maximum size of the file to validate. ### Returns `boolean` ## `isValidType` {{ tag: 'function', since: '6.11' }} This function is used to validate that a file is of a valid type given a route config. ### Parameters The type of the file to validate. The allowed types of the file to validate. ### Returns `boolean`