11
$\begingroup$

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?

$\endgroup$
5
  • $\begingroup$ 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.) $\endgroup$ Oct 31, 2014 at 14:42
  • $\begingroup$ 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. $\endgroup$
    – partida
    Oct 31, 2014 at 15:09
  • 1
    $\begingroup$ @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 $\endgroup$
    – partida
    Nov 11, 2014 at 4:59
  • 1
    $\begingroup$ If anyone knows whether this bug has been fixed, please update the bug header (see meta.mathematica.stackexchange.com/questions/1610/…). $\endgroup$
    – Michael E2
    Aug 9, 2015 at 12:03
  • 2
    $\begingroup$ @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. $\endgroup$ Dec 6, 2015 at 22:41

3 Answers 3

4
$\begingroup$

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"]
$\endgroup$
4
  • $\begingroup$ 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. $\endgroup$ Jul 28, 2020 at 20:06
  • $\begingroup$ Export["deneme.xls", "xls"] makes no sense. Please read the documentation for Export of Excel fiels. $\endgroup$ Jul 28, 2020 at 20:28
  • $\begingroup$ 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. $\endgroup$ Jul 28, 2020 at 20:50
  • $\begingroup$ I solved the problem. Thanks. $\endgroup$ Jul 28, 2020 at 21:19
11
$\begingroup$

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"
$\endgroup$
1
  • $\begingroup$ 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? $\endgroup$ Jul 28, 2020 at 20:01
3
$\begingroup$

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"]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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