我是靠谱客的博主 淡淡手机,这篇文章主要介绍web项目前端上传文件给后端,现在分享给大家,希望可以做个参考。

人工智能,零基础入门!http://www.captainbed.net/inner

1、前端

给input的type为file,加上name

form的enctype=”multipart/form-data”

请求方式为post

2、后端

后端@RequestParam(value = “file”, required = false) MultipartFile file接受
String fileName = file.getOriginalFilename();  可以获取文件名字
spring MVC 的MultipartFile
file.getInputStream() 获得io流
(int) file.getSize() 获得文件长度
file.getBytes()

3、maven依赖

<!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
<dependency>
     <groupId>commons-io</groupId>
     <artifactId>commons-io</artifactId>
     <version>2.6</version>
     </dependency>
<!-- https://mvnrepository.com/artifact/commons-fileupload/commons-fileupload -->
<dependency>
    <groupId>commons-fileupload</groupId>
    <artifactId>commons-fileupload</artifactId>
    <version>1.4</version>
</dependency>
 

最后

以上就是淡淡手机最近收集整理的关于web项目前端上传文件给后端的全部内容,更多相关web项目前端上传文件给后端内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(152)

评论列表共有 0 条评论

立即
投稿
返回
顶部