当前位置:网站首页>Method of converting file to multipartfile
Method of converting file to multipartfile
2022-06-10 23:55:00 【Li_ XiaoJin】
File To MultipartFile
introduce spring-mock rely on
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-mock</artifactId>
<version>2.0.8</version>
</dependency>
Code implementation :
File file = new File("PATH");
InputStream fileInputStream = new FileInputStream(file);
MultipartFile multipartFile = new MockMultipartFile(fileName, fileName, ContentType.APPLICATION_OCTET_STREAM.toString(), fileInputStream);
What we should pay attention to here is ContentType.APPLICATION_OCTET_STREAM.toString() , The following tape must be selected contentType Construction method of , I used to use no contentType Of , Because there are no settings contentType Resulting in subsequent generation MultipartFile Can't upload successfully . Bear in mind
public MockMultipartFile(String name,
@Nullable String originalFilename,
@Nullable String contentType,
InputStream contentStream) throws IOException
Copyright: use Creative Commons signature 4.0 International license agreement to license Links:https://lixj.fun/archives/file-to-multipartfile
边栏推荐
- Is it safe for changtou school to open an account? Is it reliable?
- 判等问题:如何确定程序的判断是正确的?
- How to remove the blank at the top of listview
- 【数学】【连续介质力学】流体力学中的对称张量、应变张量和应力张量
- Fiddler filtering sessions
- How to generate automatic references (simple drawings)
- 【Pygame小游戏】趣味益智游戏 :打地鼠,看一下能打多少只呢?(附源码)
- Perfect decoding purecodec 20220601
- Is it safe for CICC Fortune Securities to open an account? Is it reliable?
- LabVIEW uses the visa read function to read USB interrupt data
猜你喜欢

黑马头条丨腾讯薪酬制度改革引争议;英特尔全国扩招女工程师;黑马100%就业真的吗......

示波器刷新率怎么测量

LabVIEW用VISA Read函数来读取USB中断数据

Common settings for vs

LabVIEW执行串行回送测试

What Fiddler does for testing

30 | 怎么重设消费者组位移?

An adaptive size / full screen display method for iframe frames

How to measure the refresh rate of oscilloscope

【Pygame合集】回忆杀-“童年游戏”,看看你中几枪?(附五款源码自取)
随机推荐
给线程池里面线程添加名称的4种方式
Solve access denied for user 'root' @ 'localhost' (using password: yes)
示波器刷新率怎么测量
File转为MultipartFile的方法
【数学】【连续介质力学】流体力学中的对称张量、应变张量和应力张量
Ilruntime hotfix framework installation and breakpoint debugging
Basic introduction and core components of kubernetes
LabVIEW编程规范
Is it safe to open an account in Shanghai Stock Exchange?
[mathematics] [continuum mechanics] symmetry tensor, strain tensor and stress tensor in fluid mechanics
Lambda 学习记录
LabVIEW uses the visa read function to read USB interrupt data
LabVIEW获取Clamp函数找到的所有点的信息
LabVIEW用高速数据流盘
Four ways to add names to threads in the thread pool
Data and information resource sharing platform (VII)
SystemVerilog (x) - user defined type
Unity script cannot display Chinese comments of C # source code or the script created by vs does not have comments of C # source code
Expandable to Max – MCU and MPU development, using the same license
Data and information resource sharing platform (6)