solr:向 SolrQueryResponse 添加内容处置

发布于 2025-01-04 03:44:31 字数 728 浏览 1 评论 0原文

我有一个扩展 RequestHandlerBase 的自定义请求处理程序。

此处理程序的目的是搜索给定用户查询的索引。不应忽略客户端浏览器上的结果,而应将响应数据下载为文件。这是我的handleRequestBody函数代码

@Override

public void handleRequestBody(final, SolrQueryRequest req,final SolrQueryResponse res) {
    tempFile = File.createTempFile(UUID.randomUUID().toString(),".tmp", new File(FILE_PATH));
    writeSearchResultstoFile(tempFile);
    ContentStreamBase outConentStream = new ContentStreamBase.FileStream(tempFile);
    outConentStream.setContentType("application/download");
    rsp.add(RawResponseWriter.CONTENT, outConentStream);
}

问题是文件正在客户端与.part文件一起下载。 rsp.getResponseHeader().add("Content-Disposition", "filename=data.csv");

没有多大帮助。有人可以告诉我如何设置内容处置吗?

I have a custom request handler that is extending RequestHandlerBase.

The purpose of this handler is to search the index for the given user query. Instead of omitting the results on the browser at client side, the response data should be downloaded as a file. Here is my handleRequestBody function code

@Override

public void handleRequestBody(final, SolrQueryRequest req,final SolrQueryResponse res) {
    tempFile = File.createTempFile(UUID.randomUUID().toString(),".tmp", new File(FILE_PATH));
    writeSearchResultstoFile(tempFile);
    ContentStreamBase outConentStream = new ContentStreamBase.FileStream(tempFile);
    outConentStream.setContentType("application/download");
    rsp.add(RawResponseWriter.CONTENT, outConentStream);
}

The problem is the file is being downloaded with .part file at client side.
rsp.getResponseHeader().add("Content-Disposition", "filename=data.csv");

didn't help much. Could some please tell me how to set the Content-Disposition.

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

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

发布评论

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

评论(1

蓝颜夕 2025-01-11 03:44:31

由于我看到您将结果格式化为 CSV,我很好奇您是否查看过 CSVResponseFormat Solr 从 3.1 版本开始就支持

Since I see that you are formatting your results as CSV I am curious as to whether you have looked at the CSVResponseFormat that Solr has supported since release 3.1

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