Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Generate an HTTP response that prompts the browser to download as a given file name
ResourceFunction["FileDownloadResponse"][expr,"filename"] generates an HTTPResponse that informs the browser that the content should be downloaded as the given filename. | |
ResourceFunction["FileDownloadResponse"][expr,"filename",fmt] uses fmt as the ExportForm. | |
ResourceFunction["FileDownloadResponse"][expr,"filename",fmt,metadata] includes metadata as part of the HTTPResponse. |
| "StatusCode" | 200 | HTTP status code |
| "ContentType" | "text/html" | MIME type for content |
| "Cookies" | {} | cookies to handle (using CookieFunction) |
| "Headers" | {} | a list of rules giving HTTP response headers |
| "Body" | response body as a string |
| "BodyByteArray" | response body as a ByteArray object |
| "BodyBytes" | response body as a list of byte values |
| "CharacterEncoding" | character encoding in the response body (e.g. "UTF8") |
| "Properties" | list of available properties |
| "StatusCodeDescription" | plain text description of status code |
| CharacterEncoding | Automatic | character encoding to apply to the response |
| CachePersistence | Inherited | how long to keep server-side cached versions of computations that are done |
| "ContentType" | Automatic | specify a content-type header |
Generate an HTTPResponse:
| In[1]:= |
| Out[1]= |
The content disposition is set with the given file name:
| In[2]:= |
| Out[2]= |
Specify a format:
| In[3]:= |
| Out[3]= |
Provide additional metadata for the HTTPResponse:
| In[4]:= |
| Out[4]= |
The MIME type is determined automatically from the file name when a format is not explicitly given:
| In[5]:= |
| Out[5]= |
| In[6]:= |
| Out[6]= |
| In[7]:= |
| Out[7]= |
It defaults to text if unknown:
| In[8]:= |
| Out[8]= |
A format can be given explicitly to override the content type:
| In[9]:= |
| Out[9]= |
Specify custom headers:
| In[10]:= |
| Out[10]= |
| In[11]:= |
| Out[11]= |
Specify a character encoding:
| In[12]:= |
| Out[12]= |
| In[13]:= |
| Out[13]= |
Deploy a file download that is cached for 3 seconds:
| In[14]:= | ![]() |
| Out[14]= |
| In[15]:= |
| Out[15]= |
Specify a MIME type for the response:
| In[16]:= |
| Out[16]= |
Generate an HTTPResponse from a FormFunction for downloading an image:
| In[17]:= | ![]() |
| Out[17]= | ![]() |
Deploy it to the cloud:
| In[18]:= |
| Out[18]= |
Specifying the content type in the metadata will override the format:
| In[19]:= |
| Out[19]= |
Providing a content disposition header in the metadata can override the given file name:
| In[20]:= |
| Out[20]= |
| In[21]:= |
| Out[21]= |
This work is licensed under a Creative Commons Attribution 4.0 International License