Message Boards Message Boards

Upload to specific webfolder

Posted 9 years ago

This code uploads a file via a webform to your cloudserver:

CloudDeploy[
 FormFunction[{"file" -> "UploadedFile"}, 
  ( #file
    ) &,
  "HTML"],
 "test", Permissions -> "Public"]

the result is a Cloudobject of the form:

https://server/objects/user-uuid/ADDED-UUID-folder/filename

The question is how can i directly upload a file to a already existing folder without first creating the ADDED-UUID-folder?

I am able to use Copyfile[#file, CloudObject["destination"] and next DeleteDirectory but there must be a more elegant way to place the file immediately in the right folder.

here is the progress i made uploading a file. First the copying of the file to the target directory "webapps". Next the removal of the Directory.

copyremove[cobject_] := 
 Module[{temp},
  temp = FileNameSplit[cobject[[1]]];
  CopyFile[cobject, CloudObject["/webapps/" <> Last[temp]]];
  DeleteDirectory[CloudObject[FileNameJoin[Most[temp]]], 
   DeleteContents -> True];
  ]

use the function in the clouddeploy to upload a file:

CloudDeploy[
 FormFunction[{{"file", "your file please"} -> "UploadedFile"},
   ( copyremove[#file];
    Column[
     {"the picture you uploaded"},
     {CloudImport["/webapps/" <> Last[FileNameSplit[First[#file]]], 
       ImageSize -> 100]}
     ]
    ) &,
  "HTML",
  AppearanceRules -> <|
    "SubmitLabel" -> "Upload File"|> 
  ],
 "test", Permissions -> "Public"]

Note1: the "webapps" folder must exist. note2: upload something cloudimport is able to read. uploading works for pdf or mp3 but cloudimport will fail.

Okay next step is to limit the files to upload to "sound" in terms of m4a and mp3 files. This restricts the imput when you push submit. I want to restrict the browse window file extensions.

Restricted["UploadedFile", "MP3"]

I know about this construct in the desktop:

{FileNameSetter[Dynamic[f], "Open", {"Sound" -> {"*.m4a", "*.mp3"}}], 
 Dynamic[f]}

This does exactly what I need in a webform upload browse window.

Can you help me coding this into the upload webform at the beginning of this post?

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract