我的路由器类看起来像下面,我正试图上传一个视频文件,并将其存储到一个文件位置。
SpringBoot路由器.java
package com.camelrest;
import java.util.HashMap;
import java.util.Map;
import org.apache.camel.component.restlet.RestletComponent;
import org.apache.camel.spring.boot.FatJarRouter;
import org.restlet.Component;
import org.restlet.ext.spring.SpringServerServlet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.embedded.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
@SpringBootApplication
public class MySpringBootRouter extends FatJarRouter {
@Autowired
private MultipartProcessor multipartProcessor;
@Override
public void configure() {
restConfiguration().component("restlet");
rest("/upload").post().to("direct:upload");
from("direct:upload")
.to("file://E:/RestTest");
}
@Bean
public ServletRegistrationBean servletRegistrationBean() {
SpringServerServlet serverServlet = new SpringServerServlet();
ServletRegistrationBean regBean = new ServletRegistrationBean(
serverServlet, "/rest/*");
Map<String, String> params = new HashMap<String, String>();
params.put("org.restlet.component", "restletComponent");
regBean.setInitParameters(params);
return regBean;
}
@Bean
public Component restletComponent() {
return new Component();
}
@Bean
public RestletComponent restletComponentService() {
return new RestletComponent(restletComponent());
}
}
字符串
我正试图上传一个视频文件使用 Postman 如下截图:
的数据
我上传的文件的内容是用一个由camel生成的随机camel ID保存的
的
不过,我想要的文件名是通过正文
SampleVideo_1280x720_10mb.mp4
作为文件名,并从正文中删除以下内容
----------------------------948281627232093197119960
Content-Disposition: form-data; name="file"; filename="SampleVideo_1280x720_10mb.mp4"
Content-Type: video/mp4
型
因此,最终输出可以是上传的视频,其文件名与postman上传时使用的文件名相同
2条答案
按热度按时间w8ntj3qf1#
您可以使用
MimeMultipartDataFormat
来解组Multipart请求。使用此方法,将准备附件到Exchange
。在此之后,你需要以某种方式转换
Attachment
到InputStream
和填充CamelFileName
头.有了这个任务可以帮助你小Processor
.路线:
字符串
处理器:
型
如果表单中只包含单个输入,则上述方法不起作用。这是因为
MimeMultipartDataFormat
将第一个表单输入封送到body(不存储文件名),并将其他输入封送到存储文件名的附件。在这种情况下,您需要直接创建Processor
阅读InputStream
:路线:
型
处理器
型
lstz6jyr2#
在multipart/form-data请求中,字段的顺序很重要。提交时,文件字段应该是第一个。Apache camel会为所有字段创建附件对象,除了请求中的第一个字段。例如,Multipart Form data Postman request
其他领域:
个字符