Skip to content
This repository has been archived by the owner on Oct 1, 2020. It is now read-only.

Commit

Permalink
fixed the discontinued file upload
Browse files Browse the repository at this point in the history
- now you can upload files into the user workspace using binary file upload
  • Loading branch information
flahn committed Jan 25, 2018
1 parent 87d0ae9 commit 8cdb433
Showing 1 changed file with 29 additions and 31 deletions.
60 changes: 29 additions & 31 deletions R/api.R
Original file line number Diff line number Diff line change
Expand Up @@ -218,33 +218,31 @@ openeo.server$api.version <- "0.0.1"

# @put /api/users/<userid>/files/<path>
# @serializer unboxedJSON
# .uploadFile = function(req,res,userid,path) {
# if (! userid %in% names(openeo.server$users)) {
# error(res,404,paste("User id with id \"",userid, "\" was not found", sep=""))
# } else {
# user = openeo.server$users[[userid]]
# path = URLdecode(path)
#
# storedFilePath = paste(user$workspace,"files",path,sep="/")
#
# if (file.exists(storedFilePath)) {
# file.remove(storedFilePath)
# }
#
# dir.split = unlist(strsplit(storedFilePath, "/(?=[^/]+$)", perl=TRUE))
#
# message(names(req$rook.input))
# # binaryPost = readBin(con=req$rook.input,what="character")
# binaryPost = req$postBody
# dir.create(dir.split[1],recursive = TRUE,showWarnings = FALSE)
# file.create(storedFilePath,showWarnings = FALSE)
#
# #TODO we should check if the input is binary or text
# writeBin(object=binaryPost,con=file(storedFilePath,"wb"))
#
# ok(res)
# }
# }
.uploadFile = function(req,res,userid,path) {
if (! userid %in% names(openeo.server$users)) {
error(res,404,paste("User id with id \"",userid, "\" was not found", sep=""))
} else {
user = openeo.server$users[[userid]]
path = URLdecode(path)

storedFilePath = paste(user$workspace,"files",path,sep="/")

if (file.exists(storedFilePath)) {
file.remove(storedFilePath)
}

dir.split = unlist(strsplit(storedFilePath, "/(?=[^/]+$)", perl=TRUE))

req$rook.input$initialize(req$rook.input$.conn,req$rook.input$.length)

dir.create(dir.split[1],recursive = TRUE,showWarnings = FALSE)
file.create(storedFilePath,showWarnings = FALSE)

writeBin(req$rook.input$read(req$rook.input$.length),con=file(storedFilePath,"wb"),useBytes = TRUE)

ok(res)
}
}

#* @delete /api/users/<userid>/files/<path>
#* @serializer unboxedJSON
Expand Down Expand Up @@ -508,10 +506,10 @@ createAPI = function() {
handler = .downloadUserFile,
serializer = serializer_unboxed_json())

# users$handle("PUT",
# "/<userid>/files/<path>",
# handler = .uploadFile,
# serializer = serializer_unboxed_json())
users$handle("PUT",
"/<userid>/files/<path>",
handler = .uploadFile,
serializer = serializer_unboxed_json())

users$handle("DELETE",
"/<userid>/files/<path>",
Expand Down

0 comments on commit 8cdb433

Please sign in to comment.