I have a test file(test1.txt) in my desktop.This is its content.

FilePrint[FileNameJoin[{$HomeDirectory, "Desktop", "test1.txt"}]]
31.16   220.49774362741593
31.18   223.49849688143496
31.2    226.49924900492292
31.22   223.5
31.24   228.5
31.26   231.5
31.28   227.5
31.3    222.5
31.32   222.5
35.72   209.72984917230133
35.74   220.68588083509488

I try to use Import and Export in CloudDeploy.

 FormPage["fileAddress" -> 
   "String", (data = Import[#fileAddress, "Table"]; Sin[data]; 
    Export[FileNameJoin[{$HomeDirectory, "Desktop", "test.txt"}], 
     data]) &], Permissions -> "Public"]

Of course this action will get a error.But I have to say this two function can help a lot in real life.So any method or workaround can do this?


I want to create some CloudObject which have some specific function to help my friends who have no mma.I hope she upload test1.txt,then get test.txtin her local disk.Just by her browser.

  • $\begingroup$ Is something like this what you're looking for? It gives you an uploader which you can select from a file browser or click&drag into: CloudDeploy[FormFunction[{"data" -> "CSV"}, Print[#data] &]] $\endgroup$ – ktm Sep 26 '16 at 17:44
  • $\begingroup$ note the 2nd argument isn't going to work, I just wanted to demonstrate the FormFunction upload page you'll see initially. $\endgroup$ – ktm Sep 26 '16 at 17:45
  • $\begingroup$ @user6014 Wow,I have to say this is a wonderful comment.I think.it can replace that Import in my case.BTW,have you summarize other format also can realize such similar function except "CSV".Would you put your comment as a answer?I think it give very useful information to my question.And any workaround for Export? $\endgroup$ – yode Sep 26 '16 at 18:51
  • $\begingroup$ I submitted an answer which hopefully helps for half the question, in regards to Export I think it's possible but I don't have time to look into it at the moment. $\endgroup$ – ktm Sep 26 '16 at 19:01
  • $\begingroup$ @Kuba The problem of uploading files is seem to be solved by user6014.The remaining problem is how to put a result file into my local disk. $\endgroup$ – yode Sep 29 '16 at 10:41

I do not think you can automatically save to someone's file system but you can create a download link, it is up to the user to click and get it:

  {"first" -> "Number", "second" -> "Number"}, 
  Module[{f = CreateFile[]},
      "<a href=\"``\" download>Click here to save test.txt</a>"
       URLShorten @@ CloudExport[#second + #first, "Text", "test.txt", 
         Permissions -> "Public"]
  ] &
 Permissions -> "Public"

This is an example with two numbers input but you can easily use user6014's suggestion for files uploading

{"data" -> "CSV"}

and process them however you want.

| improve this answer | |
  • $\begingroup$ I will learn some knowledge of cloud then comment this answer.Thanks. :) $\endgroup$ – yode Sep 29 '16 at 19:08
  • $\begingroup$ @yode Sure, let me know how does it work for you or if you need something more. $\endgroup$ – Kuba Sep 29 '16 at 19:12
  • $\begingroup$ Not need something more.I just don't very like that link.The network is little weak in China.When I click the link,the browse sometime will give a hint that I cannot access it.So I look forward a file directly still.Well,I think the URLDownload can help.I will give a try for this tomorrow. $\endgroup$ – yode Sep 29 '16 at 19:23
  • $\begingroup$ CloudDeploy[FormPage["file"->"Table",(URLDownload[Sequence@@CloudExport[Sin[#file],"Table",Permissions->"Public"],FileNameJoin[{$HomeDirectory,"Desktop","test.txt"}]])&],"testFile",Permissions->"Public"] is what I think.It seem browser cannot do such thing. $\endgroup$ – yode Oct 2 '16 at 18:49
  • $\begingroup$ Little blemish,when I change it into CloudExport[Sin[#file], "Table", "test.txt", Permissions -> "Public"].I cannot get a real table file like Export.Actually the file is a table format. $\endgroup$ – yode Oct 2 '16 at 19:09

FormFunction allows you to upload files directly into the browser, which should bypass your need for Import. If your typespec for your FormFunction is something which Mathematica knows is a file type then it will prompt you to upload a file in the deployed page:

CloudDeploy[FormFunction[{"data" -> "CSV"}, ...

Cloud data import

I believe any of the form specifications for Interpreter are valid typespecs in FormFunction (details and options):


| improve this answer | |
  • $\begingroup$ This help me a lot,thanks. :) $\endgroup$ – yode Sep 27 '16 at 6:34
  • $\begingroup$ I realize the new function URLDownload maybe can do this. $\endgroup$ – yode Sep 29 '16 at 10:43

I have to declare that this answer is just combination with user6014's and Kuba's.I compose this for reading.I find the "Table" format maybe have some bug,which don't same to Export[*,"Table"].So I make a workaround by XLS for this target.

 FormPage["file" -> "Table", 
     "Click <a href=\"``\" download>here</a> to save as test.xls"][
    Sequence @@ 
     CloudExport[Sin[#file], "XLS", "test.xls", 
      Permissions -> "Public"]] &], Permissions -> "Public"]

You can use my test1.txt to test this cloud object.If anyone can give a method just using browser to save a file in local disk,I'd glad to kow still.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.