• 首页
  • 产品中心
    • 数式Oinone四大产品

      低代码开发平台无代码开发平台集成开发平台AI大模型开发
    • 数式Oinone体系能力

      用户与组织权限管理文件管理消息中心国际化业务审计
    • 数式Oinone核心产品特性

      低无一体面向软件公司场景无限制应用级扩容可分可合
  • 服务中心
    • 客户服务

      预约演示方案咨询私有部署找人定制
    • 开发者

      问答下载
    • Oinone学院

      社区学习

    《精讲面向软件公司的低代码平台——以Oinone为例》

  • 合作伙伴
    渠道申请伙伴名录专家库
  • 关于数式
0571-88757863

FileClient API


I. Overview

FileClient is an abstract interface used to unify file operations for different object storage services (such as Alibaba Cloud OSS, Huawei Cloud OBS, Tencent Cloud COS, MinIO, Upyun, etc.). Instances are obtained through the factory class FileClientFactory, supporting multi-CDN configurations.

(Ⅰ) Obtaining Instances

// Get the default client
FileClient fileClient = FileClientFactory.getClient();

// Get a specific client by cdnKey (used in multi-CDN configurations)
FileClient fileClient = FileClientFactory.getClient("cdnKey");

(Ⅱ) Configuration Example: Taking Alibaba Cloud OSS as an Example

cdn:
  oss:
    name: 阿里云
    type: OSS
    bucket: your-bucket-name
    uploadUrl: oss-cn-hangzhou.aliyuncs.com
    downloadUrl: oss-cn-hangzhou.aliyuncs.com
    accessKeyId: your-access-key-id
    accessKeySecret: your-access-key-secret
    mainDir: upload/
    validTime: 3600000  # Signature validity period (milliseconds)
    timeout: 600000     # Request timeout
    active: true

For more configuration references: File Storage Configuration

II. Method Descriptions

(Ⅰ) Uploading Files

1、upload(String fileName, byte[] data)

  • Description: Uploads a byte array to OSS.
  • Parameters:
    • fileName: File name (including path)
    • data: Byte array of file content
  • Returns: CdnFile containing file metadata and access URL
  • Example:
byte[] data = ...; // File content
CdnFile cdnFile = fileClient.upload("path/file.txt", data);

2、upload(String fileName, InputStream inputStream)

  • Description: Uploads a file via an input stream.
  • Parameters:
    • fileName: File name (including path)
    • inputStream: File input stream
  • Returns: CdnFile
  • Example:
try (InputStream is = new FileInputStream("local.txt")) {
    CdnFile cdnFile = fileClient.upload("path/file.txt", is);
}

3、uploadByFileName(String fileName, byte[] data)

  • Description: Uploads a file and returns the download URL.
  • Returns: File download URL (String)
  • Example:
String url = fileClient.uploadByFileName("path/image.png", imageData);

4、uploadByFileName(String fileName, InputStream inputStream)

  • Description: Uploads a file via an input stream and returns the download URL.
  • Example:
String url = fileClient.uploadByFileName("path/image.png", inputStream);

(Ⅱ) Obtaining Download URLs

1、getDownloadUrl(String fileName)

  • Description: Obtains the download URL of a file uploaded via uploadByFileName.
  • Parameters: fileName - File name used during upload
  • Returns: Complete download URL
  • Example:
String url = fileClient.getDownloadUrl("path/image.png");

(Ⅲ) Delete Operations

1、deleteByFolder(String folder)

  • Description: Deletes all files under the specified folder.
  • Parameters: folder - Folder path
  • Example:
fileClient.deleteByFolder("temp/");

2、deleteByFilename(String filename)

  • Description: Deletes the specified file.
  • Parameters: filename - Complete file name (including path)
  • Example:
fileClient.deleteByFilename("path/file.txt");

(Ⅳ) File Check

1、isExistByFilename(String filename)

  • Description: Checks if a file exists.
  • Returns: true if exists, false if not
  • Example:
boolean exists = fileClient.isExistByFilename("path/file.txt");

(Ⅴ) Obtaining Static Resource URLs

1、getStaticUrl()

  • Description: Obtains the root URL for static resources, determining whether to use CDN based on configuration.
  • Returns: URL string
  • Example:
String staticUrl = fileClient.getStaticUrl();

III. Complete Example

Batch upload files and obtain URLs

private static Map<String, String> uploadFiles(File directory) {
    Map<String, String> result = new HashMap<>();
    File[] files = directory.listFiles();
    if (files == null) return result;

    for (File file : files) {
        try (FileInputStream is = new FileInputStream(file)) {
            String fileName = "widget/" + file.getName();
            fileClient.uploadByFileName(fileName, is);
            String url = fileClient.getDownloadUrl(fileName);
            result.put(file.getName(), url);
        } catch (Exception e) {
            throw new RuntimeException("Upload failed", e);
        }
    }
    return result;
}

IV. Data Structure CdnFile

FieldTypeDescription
nameStringFile name
sizeLongFile size (bytes)
typeStringFile type
urlStringComplete access URL for the file

V. Notes

  1. Multi-CDN Configuration: Use FileClientFactory.getClient(String cdnKey) to obtain a client with specified configuration.
  2. Path Specifications: File names are recommended to include paths (e.g., "images/avatar.jpg") to avoid using the root directory directly.

VI. Supported Storage Services

Service ProviderType IdentifierImplementation Class
Alibaba Cloud OSSOSSAliyunOSSClient
Huawei Cloud OBSHUAWEI_OBSHuaweiOBSClient
Local StorageLOCALLocalFileClient
MinIOMINIOMiniOssClient
UpyunUPYUNUpyunOSSClient
Tencent Cloud COSTENCENT_COSTencentCosClient
Edit this page
Last Updated:1/15/26, 4:02 AM
Prev
Message Hub API
Next
MQ API
默认页脚
Copyright © 2026 Mr.Hope