我的休息界面是:
@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
内容类型。
有没有办法使用上述休息端点配置上传zip文件?
最佳答案
应用程序八位字节流提供文件参数
@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";
}
关于java - 使用休息服务将 zip 文件上传为八位字节流内容类型时,Zip 文件大小会受到影响,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56882644/