11

Bug introduced in 10.0 and fixed in 10.3 or earlier


I want to upload a file to the Wolfram Cloud and plot the list: So I use the following code to check its head at the beginning:

CloudDeploy[FormFunction[{"file" -> "XLS"},Head[#file]&], Permissions -> "Public"]

Output is:

CloudObject[ https://www.wolframcloud.com/objects/7d8de66e-be8b-496e-a692-124593ee3879 ]

But when I upload a XLS file and then submit,it can not continue,it throws a error:

upload a file of type XLS

enter image description here

If I check this file type on my computer:

FileFormat["F:\\learning_mma\\testfile.xls"]

result is:

XLS

So my question is how to upload a XLS file to the Clould and then plot it?

Karsten7
  • 27,448
  • 5
  • 73
  • 134
partida
  • 6,816
  • 22
  • 48
  • This is a related question and still unanswered by WRI. I did ask at the WTC conference last week, sent a mail to a main developer, but never heard back (maybe it went into a Spam folder? Or they are very very busy fixing things. Probably.) – Rolf Mertig Oct 31 '14 at 14:42
  • yes,simular this code:CloudDeploy[ FormFunction[{"image" -> "Image"}, EdgeDetect[#image] &, "JPEG"]] can run.and CloudDeploy[FormFunction[{"lis"->"List"},Length[#lis]&],Permissions->"Public"] also can run.But XLS can't be done. – partida Oct 31 '14 at 15:09
  • 1
    @Rolf Mertig I feedback to wolfram and get the answer.This is a known issue with using "UploadedFile" with FormFunction. I have updated the bug report with your case. Thank you very much for giving us feedback. Sincerely, Xin Xiao Wolfram Technical Support – partida Nov 11 '14 at 04:59
  • 1
    If anyone knows whether this bug has been fixed, please update the bug header (see http://meta.mathematica.stackexchange.com/questions/1610/standard-header-for-bugs-tagged-posts-for-easy-searching). – Michael E2 Aug 09 '15 at 12:03
  • 2
    @MichaelE2 It works now. Difficult to say which (cloud) version corrected the bug. Not really relevant though, since only the latest version (10.3 at the moment) is accessible. – Sjoerd C. de Vries Dec 06 '15 at 22:41

3 Answers3

11

So, let's hope this will be fixed in the next version. Until then this simple workaround, using "Binary" as an intermediate format, will do it:

  CloudDeploy@
         FormFunction[{"data" -> "Binary"}, 
                     (
                      CloudPut[#data, "excelFile"]; 
                      "Uploaded XLSX"
                     ) &
         ]

Then, after uploading an Excel file through the browser, you can get the content of the Excel file into Mathematica simply by:

Composition[ ImportString[#, "XLSX"] &,
             ExportString[#, "Binary"] &,
             CloudGet
] @ "excelFile"
Rolf Mertig
  • 17,172
  • 1
  • 45
  • 76
  • I tried your code above with "XLS" file but it does not work. It cannot find my Excel file in the Cloud. Is this issue solve by now? – Tugrul Temel Jul 28 '20 at 20:01
4

Suppose you create

Export["test.xls", RandomReal[1, 42]]

Then this seems to work in creating a nice plot (it will not look nice without specifying FontFamily, somehow, strangely).

CloudDeploy[
 FormFunction[{"file" -> "XLS"}, 
  ListLinePlot[Transpose[First[#file]], 
    LabelStyle -> {FontFamily -> "Tahoma", FontSize -> 16}] &], 
 Permissions -> "Public"]
Rolf Mertig
  • 17,172
  • 1
  • 45
  • 76
  • I tried the following but does not work: SetDirectory[ "D:\\World_Bank_projects\Manual_for_Math_Package\Methods_codes_and_\ articles"]; Export["deneme.xls", "xls"]; CloudDeploy[FormFunction[{"deneme" -> "XLS"}]]; Composition[ImportString[#, "XLS"] &, ExportString[#, "Binary"] &, CloudGet]@"deneme.xls". The following errors observed: `CloudObject::cloudnf: No CloudObject found at the given address

    BinaryWrite::nocoerce: $Failed cannot be coerced to the specified format.

    ImportString::string: First argument $Failed is not a string.`

    – Tugrul Temel Jul 28 '20 at 20:06
  • Export["deneme.xls", "xls"] makes no sense. Please read the documentation for Export of Excel fiels. – Rolf Mertig Jul 28 '20 at 20:28
  • I tried this Export[CloudObject["deneme"], deneme.xls, "xls"] but not working. I see the deneme.xls file on Cloud but it is empty. It should not be empty. – Tugrul Temel Jul 28 '20 at 20:50
  • I solved the problem. Thanks. – Tugrul Temel Jul 28 '20 at 21:19
3

If you're willing to use a text file instead of XLS, here's the code I use to upload & plot two columns from a text file:

CloudDeploy[FormFunction[
"x" -> "Text",
ListPlot[ImportString[#x, "Data"]] &, "PNG"
], Permissions -> "Public"]
ConvexMartian
  • 1,641
  • 11
  • 18