Group Abstract Group Abstract

Message Boards Message Boards

Can I use file upload in a FormPage? If so, how does it work?

I'm trying to CloudDeploy a simple FormPage where the user can upload a small plaintext file and the code then does stuff with the file contents. But I can't figure out how to do the file upload. From the Documentation, it looks like the "UploadedFile" interpreter type is what I need, so here's a dummy example:

CloudDeploy[FormPage[{"file"->"UploadedFile"},"Not doing anything with that file."&],Permissions->"Public"]

Using this, I get a nice little webpage with an input field that offers drag&drop or browsing to add a file. If I drag&drop, the file name flashes up for a second or so, and then the field turns red and shows the "This field is required" warning, no sign of the file. If I click the field to browse for a file, I do get a browser window, but as soon as I select a file, the same warning appears and again, no file.

I'm pretty sure I'm making a really obvious mistake here, so any pointers would be appreciated.

(I'm using Mathematica 10.4, Windows 10, and Firefox.)

POSTED BY: Bianca Eifert
2 Replies
POSTED BY: Bianca Eifert

Specify that the FormPage UploadedFile input field should not automatically submit the form:

CloudDeploy[
   FormPage[
      {"x" -> <|"Interpreter" -> Restricted["UploadedFile", "Text"], "AutoSubmitting" -> False|> },
      Import[#x, "Text"] & ], 
   FileNameJoin[{$CloudRootDirectory, "FormPageTextRestrictedAutoSubmittingFalse"}] ]
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard