Spring MVC的MultipartFile

定义

MultipartFile接口是Spring MVC中用来处理上传文件的接口,它提供了访问上传文件内容、文件名称、文件大小等信息的方法。

源码:

java 复制代码
package org.springframework.web.multipart;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import org.springframework.core.io.InputStreamSource;
import org.springframework.core.io.Resource;
import org.springframework.lang.Nullable;
import org.springframework.util.FileCopyUtils;

public interface MultipartFile extends InputStreamSource {
    String getName();

    @Nullable
    String getOriginalFilename();

    @Nullable
    String getContentType();

    boolean isEmpty();

    long getSize();

    byte[] getBytes() throws IOException;

    InputStream getInputStream() throws IOException;

    default Resource getResource() {
        return new MultipartFileResource(this);
    }

    void transferTo(File dest) throws IOException, IllegalStateException;

    default void transferTo(Path dest) throws IOException, IllegalStateException {
        FileCopyUtils.copy(this.getInputStream(), Files.newOutputStream(dest));
    }
}

方法

getOriginalFilename():获取上传文件的原始名称,包括文件的扩展名。

transferTo(File destination):将上传的文件保存到指定的目标路径。

相关推荐
色空大师几秒前
网站搭建实操(五)后台管理-短信模块
java·阿里云短信·网站·短信
极创信息4 分钟前
信创软件安全加固指南,信创软件的纵深防御体系
java·大数据·数据库·金融·php·mvc·软件工程
蜘蛛侠..17 分钟前
什么是 Plan-and-Execute 模式?与ReAct模式区别?
java·ai·大模型·llm·agent·react·plan模式
untE EADO39 分钟前
SpringBoot:几种常用的接口日期格式化方法
java·spring boot·后端
一个人说晚安41 分钟前
Docker 部署 OpenClaw 并接入第三方大模型 (MiniMax) 完整排坑指南
java·开发语言·dubbo
迷藏4941 小时前
**雾计算中的边缘智能:基于Python的轻量级任务调度系统设计与实现**在物联网(IoT)飞速发展的今天,传统云
java·开发语言·python·物联网
LSL666_1 小时前
云服务上安装nginx
java·运维·nginx
biubiubiu07061 小时前
从 Python 和 Node.js 的流行看 Java 的真实位置
java·python·node.js
我是大猴子1 小时前
队列的一些场景题以及处理方式
java
ictI CABL1 小时前
MySQL数据库的数据文件保存在哪?MySQL数据存在哪里
java