简体   繁体   English

使用rest服务将zip文件作为八位字节流内容类型上传时,zip文件的大小会受到影响

[英]Zip file size getting compromise while uploading zip file as octet-stream content type using rest service

My rest interface is: 我的休息界面是:

@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);
    }
}

I'm getting zipEntry null if I'm using APPLICATION_OCTET_STREAM content-Type. 如果我正在使用APPLICATION_OCTET_STREAM content-Type,则会得到zipEntry null。

Is there a way to upload zipfile using above rest endpoint configuration? 有没有一种方法可以使用上述其余端点配置来上传zipfile?

Application octet stream supplies File arguments 应用程序八位字节流提供文件参数

@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";
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 restTemplate 下载内容类型八位字节流的文件 - Download file of content-type octet-stream using restTemplate Spring文件上传内容类型验证,总是八位字节流? - Spring file upload content type validation, always octet-stream? 如何将二进制/八位字节流 s3 内容保存/压缩到压缩 - How to save/zip binary/octet-stream s3 content to zip 如何在其余服务中接收以八位字节流类型发送的图像? - How to receive an image send as octet-stream type in the rest service? 如何将zip文件转换为八位字节流 - How to convert a zip file into an octet stream 无法在Spring / Postman中上传多部分文件和dto对象内容类型'application / octet-stream'不支持 - Unable to upload multipart file and dto object in Spring/Postman Content type 'application/octet-stream' not supported 为什么除非我将文件命名为 .html,否则上传到 S3 的文件的内容类型为 application/octet-stream? - Why does file uploaded to S3 have content type application/octet-stream unless I name the file .html? application/octet-stream 用于文件上传 - application/octet-stream for file Upload 使用Jersey上载zip文件 - Uploading a zip file using Jersey HTTPUrlConnection和应用程序/八位字节流内容类型响应处理 - HTTPUrlConnection and application/octet-stream content-type response handling
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM