summaryrefslogtreecommitdiff
path: root/plumber.R
diff options
context:
space:
mode:
authorprashantsinalkar2019-07-10 18:11:47 +0530
committerprashantsinalkar2019-07-10 18:11:47 +0530
commit68a9af50d84bf00c58574e3708c559dc252f8123 (patch)
treef8ba8ad33894e28a6f1fb29aa1b1832b3466d7c7 /plumber.R
parenta810ada66224c4634e551dc189b18a1c35ccf724 (diff)
downloadR_on_Cloud_Web_API-68a9af50d84bf00c58574e3708c559dc252f8123.tar.gz
R_on_Cloud_Web_API-68a9af50d84bf00c58574e3708c559dc252f8123.tar.bz2
R_on_Cloud_Web_API-68a9af50d84bf00c58574e3708c559dc252f8123.zip
added upload function
Diffstat (limited to 'plumber.R')
-rw-r--r--plumber.R24
1 files changed, 24 insertions, 0 deletions
diff --git a/plumber.R b/plumber.R
index 0f091c8..099661c 100644
--- a/plumber.R
+++ b/plumber.R
@@ -68,3 +68,27 @@ robust.system <- function (cmd) {
unlink(c(stdoutFile, stderrFile))
return(retval)
}
+
+
+#* @post /upload
+upload <- function(req, res){
+ cat("---- New Request ----\n")
+ # the path where you want to write the uploaded files
+ file_path <- "/data/home/r_on_cloud/R_on_Cloud_Web_API/"
+ # strip the filename out of the postBody
+ file_name <- gsub('\"', "", substr(req$postBody[2], 55, 1000))
+ # need the length of the postBody so we know how much to write out
+ file_length <- length(req$postBody)-1
+ # first five lines of the post body contain metadata so are ignored
+ file_content <- req$postBody[5:file_length]
+ # build the path of the file to write
+ file_to_write <- paste0(file_path, file_name)
+ # write file out with no other checks at this time
+ write(file_content, file = file_to_write)
+ # print logging info to console
+ cat("File", file_to_write, "uploaded\n")
+ # return file path &name to user
+ ro <- file_to_write
+ r<- list(status = "SUCCESS", code = "200", output = ro)
+ return (r)
+}