将名称添加到春季资源对象

发布于 2025-02-12 04:39:06 字数 190 浏览 2 评论 0原文

嗨,我正在调用一个端点,该端点返回带有bytearray的弹簧资源,我需要将其传递给另一个期望弹簧资源对象的端点。 但是,不断的资源没有文件名。即将发出的资源预计将有一个文件名,因为它将其转化为EMAI附件。

在此处添加文件名的最佳方法是什么? 我一直在尝试将资源复制到文件中,而不是再次将该文件读为一个新资源,但它一直告诉MET,该位置不存在该文件。

Hi i am calling an endpoint that returns a spring resource with a byteArray in it and i need to pass this along to another endpoint that expects a spring Resource object.
But the incomming resource has no fileName. and the outgoing resource expects a filename to be present as it translates this to an emai attachment.

What is the best way to add a file name here?
I have been trying to copy the Resource to File and than read that file again into a new resource but it keeps telling met that the file does not exist in that location.

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

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

发布评论

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

评论(1

羁客 2025-02-19 04:39:06

在控制器方法中,您设置文件名

 HttpHeaders headers = new HttpHeaders();
            headers.setContentType(MediaType.APPLICATION_PDF);
            headers.setContentDispositionFormData(filename, filename);
            headers.setCacheControl("must-revalidate, post-check=0, pre-check=0");

和响应实体中

 return ResponseEntity.ok()
                .headers(headers)
                .contentLength(fileLength)
                .body(resource);

In the controller method you set the filename

 HttpHeaders headers = new HttpHeaders();
            headers.setContentType(MediaType.APPLICATION_PDF);
            headers.setContentDispositionFormData(filename, filename);
            headers.setCacheControl("must-revalidate, post-check=0, pre-check=0");

and in the response entity

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