solr dev
solr dev

Reputation: 11

solr: Adding content-disposition to SolrQueryResponse

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.

Upvotes: 1

Views: 221

Answers (1)

Paige Cook
Paige Cook

Reputation: 22555

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

Upvotes: 1

Related Questions