# HTTP.setheaders for file download

**URL:** <https://discourse.julialang.org/t/http-setheaders-for-file-download/54680>\
**Category:** General Usage\
**Tags:** http\
**Created:** [February 5, 2021, 10:46am UTC](https://discourse.julialang.org/t/http-setheaders-for-file-download/54680 "2021-02-05T10:46:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Laco\_Kovac](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/laco_kovac/32/20684_2.png) [@Laco\_Kovac](https://discourse.julialang.org/u/Laco_Kovac)\
**Post date:** [February 5, 2021, 10:46am UTC](https://discourse.julialang.org/t/http-setheaders-for-file-download/54680/1 "2021-02-05T10:46:13Z")

</div>

This is the code of web server. In this rest api response, I want the text to be downloaded in the file named results.csv (i.e. user should get the file “results.csv” in the Downloads folder).

Here is the code:

```julia
if lastUriItem == "table"
    http = HTTP.Response(200, sText)
    # we have to set the response type
    HTTP.setheader(http, "Content-Type" => "application/force-download")
    HTTP.setheader(http, "Content-Disposition" => "attachment");
    HTTP.setheader(http, "filename" => "results.csv");
    HTTP.setheader(http, "Content-Transfer-Encoding" => "binary");
    HTTP.setheader(http, "Content-Length" => string(length(sText)));
    return http
end

```

When I type in exact URL to the browser, it downloads file “table” (no extension), and it contains the text I provided as sText.  
When I use this in a swagger-ui (and this may be a problem in the swagger code, I don’t know), the name of the downloaded file is something very long & horrible, with parts of URL, e.g.:  
application\_force-download\_table\_forecastType=outOfSampleRows&forecastType=production&modelIndex=1\_blob\_http\_\_\_localhost\_8080\_64505337-ef14-46fe-89f8-9af8dbc2c536  
(again, no extension)

Is there something better I could do in my code make downloaded file to be “results.csv”?

Thank you,

---

<div class="post-metadata">

**Author:** ![pixel27](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pixel27/32/8902_2.png) [@pixel27](https://discourse.julialang.org/u/pixel27)\
**Post date:** [February 5, 2021, 3:09pm UTC](https://discourse.julialang.org/t/http-setheaders-for-file-download/54680/2 "2021-02-05T15:09:07Z")

</div>

You specify the filename in the Content-Disposition header. So it should be:

```julia
 HTTP.setheader(http, "Content-Disposition" => "attachment; filename=\"results.csv\"");

```

You might find this helpful:

> **[Content-Disposition - HTTP | MDN](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition)**
>
> In a regular HTTP response, the Content-Disposition response header is a header indicating if the content is expected to be displayed inline in the browser, that is, as a Web page or as part of a Web page, or as an attachment, that is downloaded and...
