8
$\begingroup$

I have a FormFunction that should work only with CSV files, something like:

CloudDeploy[FormFunction[{"file" -> "CSV"}, Dimensions[#file] & ], Permissions -> "Public"] 

How can I create a restriction so only CSV files can be submitted?

enter image description here

I want to show a message saying "only CSV files can be uploaded" when someone tries to load an image, and prevent the submit.

I tried this, didn't work:

CloudDeploy[ FormFunction[{"file" -> <|"Interpreter" -> Restricted["CSV"]|>}, Dimensions[#file] & ], Permissions -> "Public"] 
$\endgroup$

1 Answer 1

9
$\begingroup$

Instead of having FormFunction directly convert CSV input into a table of values, upload the CSV file to a CloudObject and do the CSV import in the cloud:

CloudDeploy[ FormFunction[{"x" -> Interpreter[Restricted["UploadedFile", "CSV"]]}, Dimensions[Import[#x, "CSV"]] & ], FileNameJoin[{$CloudRootDirectory, "CSVRestrictedUploadedFile"}], Permissions -> "Public" ] 

An attempt to submit a file other than type CSV will fail and generate an “Enter a file of type CSV” alert under the error condition input field:

Enter CSV file

See documentation "UploadedFile" (interpreter type).

$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.