Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Infiniflow Ragflow File Util

From Leeroopedia
Knowledge Sources
Domains Frontend, File_Management, Utilities
Last Updated 2026-02-12 06:00 GMT

Overview

Concrete comprehensive file handling utilities for image compression, base64 conversion, file downloads, and MIME type detection in the RAGFlow frontend.

Description

The utils/file-util.ts module provides functions for: compressing images using canvas (compressImage), converting files to base64 strings, triggering browser file downloads, detecting file MIME types from extensions, and validating file sizes.

Usage

Import these utilities for avatar upload image compression, file download triggers, and file type validation in upload components.

Code Reference

Source Location

Signature

export function compressImage(file: File, maxWidth: number, quality: number): Promise<Blob>;
export function fileToBase64(file: File): Promise<string>;
export function downloadFile(url: string, filename: string): void;
export function getMimeType(filename: string): string;

Import

import { compressImage, fileToBase64, downloadFile } from '@/utils/file-util';

I/O Contract

Inputs

Name Type Required Description
file File Yes File to compress or convert
maxWidth number Yes Maximum image width (for compressImage)
url string Yes Download URL (for downloadFile)

Outputs

Name Type Description
compressImage() Promise<Blob> Compressed image blob
fileToBase64() Promise<string> Base64-encoded file content

Usage Examples

import { compressImage, downloadFile } from '@/utils/file-util';

const compressed = await compressImage(avatarFile, 200, 0.8);
downloadFile('/api/v1/document/download/doc123', 'report.pdf');

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment