我的休息界面是:
@POST
@Path ("/xy/v1/xyz")
@Consumes({ MediaType.APPLICATION_OCTET_STREAM})
@Produces({ MediaType.APPLICATION_JSON })
Response import(InputStream fileInputStream, @Context HttpHeaders headers,
@Context HttpServletRequest httpServletRequest,
@Context UriInfo info) {
try (ZipInputStream zipInputStream = new
ZipInputStream(fileInputStream))
{
ZipEntry zipEntry = zipInputStream.getNextEntry();
while (zipEntry != null)
{
if(!zipEntry.isDirectory())
{
data= new String(IOUtils.toByteArray(zipInputStream));
fileName = zipEntry.getName().substring(zipEntry.getName().lastIndexOf("/")+1);
list.add(
//...
);
}
zipInputStream.closeEntry();
zipEntry = zipInputStream.getNextEntry();
}
}
catch (IOException e)
{
LOG.error("Exceptions occured while reading",e);
}
}
如果我使用APPLICATION_OCTET_STREAM
,则会得到zipEntry null
内容类型。
是否可以使用上述其余端点配置来上传zipfile?
答案 0 :(得分:0)
应用八位字节流提供文件参数
@POST
@Path("upload")
@Consumes(MediaType.APPLICATION_OCTET_STREAM)
@Produces(MediaType.TEXT_PLAIN)
public String upload(File f) {
// ... The file contains the data uploaded
return "ok";
}