建購物網(wǎng)站怎么建呀微商怎么做推廣加好友
定義
MultipartFile接口是Spring MVC中用來處理上傳文件的接口,它提供了訪問上傳文件內(nèi)容、文件名稱、文件大小等信息的方法。
源碼:
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();@NullableString getOriginalFilename();@NullableString 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():獲取上傳文件的原始名稱,包括文件的擴(kuò)展名。
transferTo(File destination):將上傳的文件保存到指定的目標(biāo)路徑。