Jersey Multipart文件下载客户端中的mimexxx.tmp文件;文件夹

发布于 2025-02-11 08:29:48 字数 779 浏览 0 评论 0原文

我的要求是使用REST API从服务器下载大文件,我将Java与泽西岛框架和Multipart_form_data类型一起发送和接收文件。 API工作正常,但是当我执行reverse..ReadEntity(formDatamultipart.Class)时,问题在客户端,它将在Java的“ Java.io.io.tmpdir”文件夹中复制整个多部分数据。是否有任何方法可以避免它或任何API/配置来更改泽西岛多部分临时目录路径(“ Java.io.tmpdir”除外)。 以下是我的示例客户端代码:

    Invocation.Builder invocationBuilder = webTarget.request(MediaType.MULTIPART_FORM_DATA_TYPE);
    Response response = invocationBuilder.get();
    FormDataMultiPart objMultiPart = response.readEntity(FormDataMultiPart.class);
    List<BodyPart> listBodyPart = objMultiPart.getBodyParts();
    try(FileOutputStream out = new FileOutputStream(filePath.toFile(), true)){
        for(BodyPart part : listBodyPart) {
            //code to process each bodypart
        }
    }

My requirement is to download large file from server using rest API, I am using java with Jersey framework and MULTIPART_FORM_DATA type for sending and receiving the file. API is working fine, but the problem is at client side when I do response.readEntity(FormDataMultiPart.class) it copies the entire multipart data in java's "java.io.tmpdir" folder. Is there any way to avoid it or any api/configuration to change jersey multipart temp directory path (other than "java.io.tmpdir").
Below is my sample client code:

    Invocation.Builder invocationBuilder = webTarget.request(MediaType.MULTIPART_FORM_DATA_TYPE);
    Response response = invocationBuilder.get();
    FormDataMultiPart objMultiPart = response.readEntity(FormDataMultiPart.class);
    List<BodyPart> listBodyPart = objMultiPart.getBodyParts();
    try(FileOutputStream out = new FileOutputStream(filePath.toFile(), true)){
        for(BodyPart part : listBodyPart) {
            //code to process each bodypart
        }
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文