排除内容元数据添加到使用WebClient Springboot的文件上传的内容

发布于 2025-02-13 05:47:09 字数 759 浏览 1 评论 0原文

我正在尝试使用Spring引导中的WebClient上传到FTP服务器。

以下是我的代码:

URI uri = new URI(domain +folderName+ fileName);
MultipartBodyBuilder builder = new MultipartBodyBuilder();
builder.part("file", resource);
ResponseEntity<Object> response = webClient.put().uri(uri).contentType(MediaType.MULTIPART_FORM_DATA)
                    .header(HttpHeaders.AUTHORIZATION, auth)                     
 .body(BodyInserters.fromMultipartData(builder.build())).retrieve().toEntity(Object.class).block();

但是,当文件上传时,我可以看到内容元数据包含在文件顶部,如下所示:

“在此处输入图像描述”

如何避免在文件中添加此内容元数据?

I am trying to upload a file to ftp server using WebClient in spring boot.

Below is my code:

URI uri = new URI(domain +folderName+ fileName);
MultipartBodyBuilder builder = new MultipartBodyBuilder();
builder.part("file", resource);
ResponseEntity<Object> response = webClient.put().uri(uri).contentType(MediaType.MULTIPART_FORM_DATA)
                    .header(HttpHeaders.AUTHORIZATION, auth)                     
 .body(BodyInserters.fromMultipartData(builder.build())).retrieve().toEntity(Object.class).block();

However, when the file gets uploaded, I can see content meta-data being included at the top of the file as seen below:

enter image description here

How do I avoid this content meta-data getting added in my file?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱冒险 2025-02-20 05:47:09

frommultipartdata(builder.build()) fromResource(new filesystemsource(resource))

,您可以完全删除

MultipartBodyBuilder builder = new MultipartBodyBuilder();
builder.part("file", resource);

我知道我在这里迟到了,但是这个答案可以帮助某人

Replace fromMultipartData(builder.build()) with fromResource(new FileSystemResource(resource))

and you can completely remove

MultipartBodyBuilder builder = new MultipartBodyBuilder();
builder.part("file", resource);

I know i am late here, but this answer may assist someone

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文