Integration with Media Kit
The @blocklet/uploader package is designed for seamless, zero-configuration integration with the Media Kit blocklet. Media Kit provides a centralized service for media storage, management, and processing. When the Uploader component detects that Media Kit is installed in the same environment, it automatically enhances its functionality without requiring any extra setup from the developer.
This automatic integration centralizes file storage, enforces consistent upload rules across all your blocklets, and dynamically enables advanced features like AI Image Generation. While this behavior is enabled by default for a streamlined experience, you can also opt-out if you need to handle uploads within your own blocklet's backend.
How It Works: Automatic Detection and Configuration#
The integration process is fully automated and follows a simple two-step process upon component initialization:
- Detection: The
Uploadercomponent scans the environment for any installed blocklet with the unique DID of Media Kit (z8ia1mAXo8ZE7ytGF36L5uBf9kD2kenhqFGp9). - Configuration: If Media Kit is found, the Uploader makes an API request to its
/api/uploader/statusendpoint. This endpoint returns a configuration object containing: - Upload Restrictions: Global rules such as
maxFileSizeandallowedFileTypesthat are centrally managed in the Media Kit. - Available Plugins: A map of which advanced plugins (e.g.,
AIImage,Resources,Uploaded) are enabled and should be displayed in the Uploader UI. - API Endpoints: The Uploader automatically configures itself to route all file uploads and related API calls to the Media Kit's services, ensuring all media is stored in one central location.
- Upload Restrictions: Global rules such as
The following diagram illustrates this automatic configuration flow:
Core Benefits#
Integrating with Media Kit offers several powerful advantages with no additional development effort.
Centralized Media Management
All uploaded files are stored and managed within the Media Kit, creating a single source of truth for media assets across multiple blocklets. The `Resources` and `Uploaded` plugins allow users to easily browse and reuse existing assets.
Dynamic Feature Plugins
Advanced features like the AI Image Generation plugin are enabled automatically if the capability is turned on in the Media Kit. This allows your application to gain new features without any code changes.
Consistent Upload Rules
Upload restrictions are defined once in the Media Kit and automatically applied to every instance of the Uploader, ensuring consistency and simplifying policy management.
Zero Backend Setup
Because Media Kit provides the necessary backend services for file processing and storage, you don't need to install or configure `@blocklet/uploader-server` in your own blocklet, reducing complexity.
Opting Out: Disabling the Integration#
In scenarios where you need to manage uploads using your own backend logic and storage (with @blocklet/uploader-server), you can disable the automatic integration with Media Kit. This is done by passing specific props to the apiPathProps object on the Uploader component.
disableMediaKitStatus: Set totrueto prevent the Uploader from fetching configuration (restrictions and plugins) from the Media Kit.disableMediaKitPrefix: Set totrueto prevent the Uploader from routing API requests to the Media Kit's endpoints. Instead, it will use the prefix of the current blocklet.
Uploader with Media Kit Integration Disabled
import { Uploader } from '@blocklet/uploader/react';
export default function MyComponent() {
return (
<Uploader
popup
apiPathProps={{
// Prevents fetching remote config from Media Kit
disableMediaKitStatus: true,
// Prevents routing API calls to Media Kit
disableMediaKitPrefix: true,
}}
// You would now need to provide your own restrictions
// and configure your own backend with @blocklet/uploader-server.
coreProps={{
restrictions: {
maxFileSize: 1024 * 1024 * 5, // 5MB
allowedFileTypes: ['image/jpeg', 'image/png'],
},
}}
/>
);
}By setting these properties, the Uploader component will operate in a standalone mode, relying entirely on its own props and the backend services configured within your application. You can learn more about this in the Backend Setup guide.