byte数组与MultipartFile的相互转化

MultipartFile转化为byte数组

byte[] bytes = multipartFile.getBytes();

byte数组转化MultipartFile
使用spring-test中的MockMultipartFile

        <dependency>
            <groupId>org.springframeworkgroupId>
            <artifactId>spring-testartifactId>
            <version>5.3.20version>
        dependency>
InputStream inputStream = new ByteArrayInputStream(bytes);
MultipartFile fileResult = new MockMultipartFile(ContentType.APPLICATION_OCTET_STREAM.toString(), inputStream);

你可能感兴趣的:(spring,java,后端)