I want to create a FormFunction that takes in a CSV file, applies some operations on the data and outputs another CSV file. I would like for the ouput CSV file to be automatically downloaded.
I have a piece of code that works, but the way it outputs depends on the OS/Browser. Here are the tests I made so far:
- MacOS + Chrome: automatically downloads the CSV (which is what I want)
- MacOS + Safari: prints the table in the browser screen.
- Linux + Firefox or Linux + Chrome: automatically download the file, but does not include the CSV extension.
Here is the example code:
func[x_] := 10 x;
CloudDeploy[
FormFunction[{
"x" -> Interpreter[Restricted["UploadedFile", "CSV"]]},
func@Import[#x] &, "CSV"],
FileNameJoin[{$CloudRootDirectory, "StackExample"}],
Permissions -> "Public"]
Is there an option I can give to FormFunction or ExportForm, to force the file to be downloaded?
You can test using this URL. And, to create a sample input table, one may use
Export["example.csv", {{1, 2, 3}, {4, 5, 6}}]