Fegin 多媒体上传调用

简介: 先分享点小福利给程序员,阿里云的优惠券,购买服务器更便宜点我获取阿里云优惠券multipart/form-dataSpring MVC中关于关于Content-Type类型信息的使用 首先我们来看看RequestMapping中的Class定义:[html] view plain copy@Target({ElementType.

先分享点小福利给程序员,阿里云的优惠券,购买服务器更便宜

点我获取阿里云优惠券

multipart/form-data

Spring MVC中关于关于Content-Type类型信息的使用
    首先我们来看看RequestMapping中的Class定义:
[html] view plain copy
@Target({ElementType.METHOD, ElementType.TYPE})  
@Retention(RetentionPolicy.RUNTIME)  
@Documented  
@Mapping  
public @interface RequestMapping {  
      String[] value() default {};  
      RequestMethod[] method() default {};  
      String[] params() default {};  
      String[] headers() default {};  
      String[] consumes() default {};  
      String[] produces() default {};  
}  
value:  指定请求的实际地址, 比如 /action/info之类。
method:  指定请求的method类型, GET、POST、PUT、DELETE等
consumes: 指定处理请求的提交内容类型(Content-Type),例如application/json, text/html;
produces:    指定返回的内容类型,仅当request请求头中的(Accept)类型中包含该指定类型才返回
params: 指定request中必须包含某些参数值是,才让该方法处理
headers: 指定request中必须包含某些指定的header值,才能让该方法处理请求
其中,consumes, produces使用content-typ信息进行过滤信息;headers中可以使用content-type进行过滤和判断。
3. 使用示例
  3.1 headers
[html] view plain copy
@RequestMapping(value = "/test", method = RequestMethod.GET, headers="Referer=http://www.ifeng.com/")    
public void testHeaders(@PathVariable String ownerId, @PathVariable String petId) {        
  // implementation omitted    
}   
  这里的Headers里面可以匹配所有Header里面可以出现的信息,不局限在Referer信息。
public static void stream2Multi() throws Exception {

        // 读入 文件 
        File file = new File("E:\\模版0720.xls");
        FileInputStream in_file = new FileInputStream(file);

        // 转 MultipartFile
        MultipartFile multi = new MockMultipartFile("模板.xls", in_file);
        String name = multi.getOriginalFilename();

        // 创建文件夹
        String dire = "E:/文件/picture/file.xls";
        File file_dire = new File(dire);
        if (!file_dire.exists()) {
            file_dire.createNewFile();
        }

        //写入文件 
        multi.transferTo(file_dire);
    }
org.springframework.web.multipart.MultipartException: Current request is not a multipart request
    at org.springframework.web.method.annotation.RequestParamMethodArgumentResolver.handleMissingValue(RequestParamMethodArgumentResolver.java:190)
    at org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver.resolveArgument(AbstractNamedValueMethodArgumentResolver.java:109)
    at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:121)
Caused by: java.io.IOException: org.apache.tomcat.util.http.fileupload.FileUploadException: the request was rejected because no multipart boundary was found
    at org.apache.catalina.connector.Request.parseParts(Request.java:2874)
    at org.apache.catalina.connector.Request.parseParameters(Request.java:3177)
    at org.apache.catalina.connector.Request.getParameter(Request.java:1110)
    at org.apache.catalina.connector.RequestFacade.getParameter(RequestFacade.java:381)
    at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:75)
    ... 30 more
Caused by: org.apache.tomcat.util.http.fileupload.FileUploadException: the request was rejected because no multipart boundary was found

我的官网
我的博客

我的官网http://guan2ye.com
我的CSDN地址http://blog.csdn.net/chenjianandiyi
我的简书地址http://www.jianshu.com/u/9b5d1921ce34
我的githubhttps://github.com/javanan
我的码云地址https://gitee.com/jamen/
阿里云优惠券https://promotion.aliyun.com/ntms/act/ambassador/sharetouser.html?userCode=vf2b5zld&utm_source=vf2b5zld

阿里云教程系列网站http://aliyun.guan2ye.com

1.png

我的开源项目spring boot 搭建的一个企业级快速开发脚手架

1.jpg

相关文章
|
2月前
【微信公众平台对接】有关【上传图文消息内的图片获取URL】调用示例
【微信公众平台对接】有关【上传图文消息内的图片获取URL】调用示例
48 0
|
2月前
|
数据采集 监控 安全
各种业务场景调用API代理的API接口教程
API代理的API接口在各种业务场景中具有广泛的应用,本文将介绍哪些业务场景可以使用API代理的API接口,并提供详细的调用教程和代码演示,同时,我们还将讨论在不同场景下使用API代理的API接口所带来的好处。
|
JSON 数据格式
Feign调用文件下载服务接口实例
Feign调用文件下载服务接口实例
1078 0
Feign调用文件下载服务接口实例
|
10月前
微信录音上传至七牛云控制器代码
微信录音上传至七牛云控制器代码
61 0
|
6月前
uniapp 请求接口的方式
uniapp 请求接口的方式
99 1
|
6月前
|
前端开发 Java 对象存储
使用Feign接口实现文件上传的解决方案
一般的情况下,后端有个微服务,暴露出一个文件上传的restful接口给前端,前端调用该接口获取上传后的链接以及oss key值完成上传。假设提供restful接口的这个服务叫做A,现在有个微服务B有个本地文件,需要将本地文件调用A文件文件上传接口上传到文件服务器,该如何做?
62 0
|
9月前
|
数据采集 算法 数据可视化
Unity实现camera数据注入RMP推送或轻量级RTSP服务模块
Unity实现camera数据注入RMP推送或轻量级RTSP服务模块
|
10月前
uniapp视频、音频上传的方法
uniapp视频、音频上传的方法
|
XML 消息中间件 JavaScript
服务端自定义生成PDF的几种方案
服务端自定义生成PDF的几种方案
|
API
网址拦截查询接口API源码
获取的是拦截官网的数据,可以查询QQ和微信的是否被拦截,此源码为网址拦截接口API
97 0