multipartfile java_java 怎么把 File 类型转 MultipartFile呀

MultipartFile是spring的一个接口,通常我们可以在controller定义方法使用MultipartFile接收form表单提交的文件,然后将MultipartFile可以转化成一个文件。

/**

* A representation of an uploaded file received in a multipart request.

*

*

The file contents are either stored in memory or temporarily on disk.

* In either case, the user is responsible for copying file contents to a

* session-level or persistent store as and if desired. The temporary storages

* will be cleared at the end of request processing.

*/

public interface MultipartFile {}

这个接口通常是用来接收上传的文件,要将文件转换成MultipartFile文件,那么实际上应该考虑的是将File转换成CommonsMultipartFile。CommonsMultipartFile的构造器需要一个FileItem的参数,FileItem有一个实现类叫DefaultFileItem,DefaultFileItem 是apache.commons.fileupload下面的一个类。问题回到了需要去看一下apache的fileupload的源码,然后自己实现文件的上传。这个源码我没有去仔细阅读。楼主可以自己去看看

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值