【发布时间】:2019-09-02 03:27:25
【问题描述】:
我试图用 RestEasy 和 Jboss 制作一个多文件上传器,但我只能上传一个文件。 我在网上找了几个小时,但没有找到例子......
@POST
@Path("/upload")
@Consumes("multipart/form-data")
public Response uploadFile(@MultipartForm FileUploadForm form) {
String fileName = form.getFileName() == null ? "Unknown" : form.getFileName() ;
String completeFilePath = "c:/temp/" + fileName;
try
{
//Save the file
File file = new File(completeFilePath);
if (!file.exists())
{
file.createNewFile();
}
FileOutputStream fos = new FileOutputStream(file);
fos.write(form.getFileData());
fos.flush();
fos.close();
}
catch (IOException e)
{
e.printStackTrace();
}
//Build a response to return
return Response.status(200)
.entity("uploadFile is called, Uploaded file name : " + fileName).build();
}
也尝试使用 request(Servlet) 但说:
org.jboss.resteasy.spi.UnhandledException: java.lang.IllegalStateException: UT010057: Servlet 上不存在多部分配置
非常感谢
【问题讨论】:
-
我建议您单独上传每个文件。没有理由把它放在一个大请求中。
-
@maio290 但我需要同时上传所有文件
标签: java rest file-upload