- Creating a “Media Library” that contains images for use throughout your site or app
- Building a Gated Content library where users need to sign up to gain access to downloadable assets like ebook PDFs, whitepapers, etc.
- Storing publicly available, downloadable assets like software, ZIP files, MP4s, etc.
filename,mimeType, andfilesizefields will be automatically added to your Collection. Optionally, if you declare image sizes asvariantsonsharpTransformer, avariantsgroup will also be added containing auto-resized image sizes and filenames.- The Admin Panel will modify its built-in
Listcomponent to show a thumbnail for each upload within the List View - The Admin Panel will modify its
Editview(s) to add a new set of corresponding Upload UI which will allow for file upload - The
create,update, anddeleteCollection operations will be modified to support file upload, re-upload, and deletion
Enabling Uploads
Every FrogBot Collection can opt-in to supporting Uploads by specifying theupload property on the Collection’s config to either true or to an object containing upload options.
Collection Upload Options
Setupload: true for the defaults, or pass an object with these options. Image processing (sizes, resizing, format, trim, metadata, crop and focal point) is configured on sharpTransformer; see Image Sizes.
FrogBot-wide Upload Options
The rootupload option configures how multipart requests are parsed for every upload-enabled collection. It combines file handling options with the options of the busboy parser. Root bodyParser options are applied first, and upload options override them.
Upload limits
A common example of what you might want to customize within FrogBot-wide Upload options would be to increase the allowed
fileSize of uploads sent to FrogBot:
Custom filename via hooks
You can customize the filename before it’s uploaded to the server by using abeforeOperation hook.
req.file object will have additional information about the file, such as mimeType and extension, and you also have full access to the file data itself.
The filename from here will also be threaded to image sizes if they’re enabled.
Image Sizes
If you declare image sizes, FrogBot will automatically crop and resize your uploads to fit each of them. The Admin Panel shows every size, with its width, height, and file size. Image sizes, declared asvariants, and the rest of the image options are configured on sharpTransformer from @frogbotai/transformer-sharp, which resizes with sharp. The blank template installs it. Without a transformer, FrogBot stores uploads as they are and shows no crop or focal point tools.
collections accepts these options:
sharpTransformer({ dynamic: true }) also resizes on request, through ?width= and ?height= on the file URL. Registering any transformer changes the file endpoint: a file is served only when it belongs to an upload document.
Image size options
Each entry invariants is an ImageSize. Besides the options below, it accepts every sharp resize option.
When a document has a focal point and the size’s aspect ratio differs from the image, FrogBot crops around the focal point instead of applying
position, unless fit is 'contain' or 'inside'.
Admin List View Options
Each image size also supportsadmin options to control whether it appears in the Admin Panel list view.
This is useful for hiding large or rarely used image sizes from the list view UI while still keeping them available in the API.
Accessing the resized images in hooks
All auto-resized images are exposed to be reused in hooks and similar via an object that is bound toreq.payloadUploadSizes.
The object will have keys for each size generated, and each key will be set equal to a buffer containing the file data.
Handling Image Enlargement
When an uploaded image is smaller than the defined image size, we have 3 options:withoutEnlargement: undefined | false | true
undefined[default]: uploading images with smaller width AND height than the image size will return nullfalse: always enlarge images to the image sizetrue: if the image is smaller than the image size, return the original image
Custom file name per size
Each image size supports agenerateImageName function that can be used to generate a custom file name for the resized image.
This function receives the original file name, the resize name, the extension, height and width as arguments.
Crop and Focal Point Selector
This feature is only available for image file types, withsharpTransformer registered.
Setting crop: false and focalPoint: false on sharpTransformer({ collections }) for a collection disables the respective selector in the Admin Panel.
Cropping changes the main image. Variants are generated from the retained original, so cropping the main image does not also crop them. The focal point controls how variants are framed.
The focal point selector is shown only when the collection has variants or image adjustments (resizeOptions, formatOptions, trimOptions, constructorOptions, or withMetadata), or when focalPoint is true.
Disabling Local Upload Storage
If you are using a plugin to send your files off to a third-party file storage host or CDN, like Amazon S3 or similar, you may not want to store your files locally at all. You can prevent FrogBot from writing files to disk by specifyingdisableLocalStorage: true on your collection’s upload config.
Admin Thumbnails
You can specify how FrogBot retrieves admin thumbnails for your upload-enabled Collections with one of the following:adminThumbnailas a string, equal to one of your variant names (declared onsharpTransformer).
adminThumbnailas a function that takes the document’s data and sends back a full URL to load the thumbnail.
Customizing the Upload UI
Use the publicUploadField component to customize a field that selects uploaded documents while retaining its form integration.
Upload Component Configuration
Setadmin.components.Field on an Upload field in your Collection Config:
Building Custom Upload Components
WrapUploadField from @frogbotai/ui/admin and forward the provided props, including permissions and read-only state. Render this component through the field slot so it receives the Admin Panel’s form and upload providers.
Basic Example
Client Component (src/components/CustomUploadField.tsx):
Available Hooks and Components
When building custom upload components, you have access to several useful hooks and components from@frogbotai/ui/admin:
Custom Upload Fields vs. Custom Upload Collections
The example above customizes an upload relationship field. Replacing an upload collection’s file editor is a separate extension point:@frogbotai/ui/admin does not export the complete collection Upload editor. Keep the default collection editor unless you are implementing its file, form, and upload-state integration yourself. UploadField and UploadInput select related documents; they are not replacements for that collection slot.
Component Export Syntax
Custom components are referenced using file paths. Both default exports and named exports are supported:Restricted File Types
Possibly problematic file types are automatically restricted from being uploaded to your application. If your Collection has defined mimeTypes or has setallowRestrictedFileTypes to true, restricted file verification will be skipped.
Restricted file types and extensions:
MimeTypes
Specifying themimeTypes property can restrict what files are allowed from the user’s file picker. This accepts an array of strings, which can be any valid mimetype or mimetype wildcards
Some example values are: image/*, audio/*, video/*, image/png, application/pdf
Example mimeTypes usage:
Uploading Files
To upload a file, use your collection’screate endpoint. Send it all the data that your Collection requires, as well as a file key containing the file that you’d like to upload.
Send your request as a multipart/form-data request, using FormData if possible.
Uploading Files stored locally
If you want to upload a file stored on your machine directly using thefrogbot.create method, for example, during a seed script,
you can use the filePath property to specify the local path of the file.
data property should still include all the required fields of your media collection.
Uploading Files from Remote URLs
ThepasteURL option allows users to fetch files from remote URLs by pasting them into an Upload field. This option is enabled by default and can be configured to either allow unrestricted client-side fetching or restrict server-side fetching to specific trusted domains.
By default, FrogBot uses client-side fetching, where the browser downloads the file directly from the provided URL. However, client-side fetching will fail if the URL’s server has CORS restrictions, making it suitable only for internal URLs or public URLs without CORS blocks.
To fetch files from restricted URLs that would otherwise be blocked by CORS, use server-side fetching by configuring the pasteURL option with an allowList of trusted domains. This method ensures that FrogBot downloads the file on the server and streams it to the browser. However, for security reasons, only URLs that match the specified allowList will be allowed.
Configuration Example
Here’s how to configure the pasteURL option to control remote URL fetching:CORS policy like the pasteURL option does, but it allows you to skip the safe fetch check for specific URLs.
Accepted Values for pasteURL
AllowItem Properties
A URL is allowed when it matches every property set on at least one entry. Unset properties match anything.
skipSafeFetch accepts the same AllowItem array.
Access Control
All files that are uploaded to each Collection automatically support theread Access Control function from the Collection itself. You can use this to control who should be allowed to see your uploads, and who should not.
Modifying response headers
You can modify the response headers for files by specifying themodifyResponseHeaders option in your upload config. This option accepts an object with existing headers and allows you to manipulate the response headers for media files.
Modifying existing headers
With this method you can directly interface with theHeaders object and modify the existing headers to append or remove headers.
Return new headers
You can also return a newHeaders object with the modified headers. This is useful if you want to set new headers or remove existing ones.