7
$\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$
8
$\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).

| improve this answer | |
$\endgroup$

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.