63 lines
1.7 KiB
R
63 lines
1.7 KiB
R
#
|
|
# StorageHubCL.R
|
|
#
|
|
# version: 1.0
|
|
# author: Giancarlo Panichi
|
|
# date: 2020/10/09
|
|
|
|
# GoogleVIS is very verbose
|
|
#suppressPackageStartupMessages(library(googleVis))
|
|
|
|
library(XML)
|
|
require(XML)
|
|
library(jsonlite)
|
|
library(stringr)
|
|
library(httr)
|
|
require("httr")
|
|
|
|
|
|
discoverStorageHub<-function(){
|
|
|
|
urlString = paste("http://registry.d4science.org/icproxy/gcube/service/GCoreEndpoint/DataAccess/StorageHub?gcube-token=",token,sep="")
|
|
got<-GET(urlString, timeout(1*3600))
|
|
xmlfile <- xmlTreeParse(got)
|
|
class(xmlfile)
|
|
xmltop = xmlRoot(xmlfile)
|
|
|
|
listxpath = xpathSApply(xmltop, "//Results/Result")
|
|
print(listxpath)
|
|
listx<-(rapply(listxpath, function(x) head(x, 1)))
|
|
if (length(listx)>0){
|
|
storagehubEP<<-as.character(listx[which(listx=="Endpoint")[[1]]+3])
|
|
}else{
|
|
cat("Found no storage ub endpoint\n")
|
|
}
|
|
|
|
}
|
|
|
|
|
|
downloadSH<-function(itemid,filename){
|
|
cat("About to download",itemid,"\n")
|
|
cat("Downloading...\n")
|
|
reqDownload<<-paste(sep="",storagehubEP,"/items/",itemid,"/download?exclude=hl:accounting&gcube-token=",token);
|
|
download.file(url = reqDownload, destfile = filename, method="wget", quiet = T, mode = "w",cacheOK = FALSE)
|
|
cat("All done.\n")
|
|
}
|
|
|
|
uploadSH<-function(folderitemid,localfilename,filename, descr){
|
|
cat("About to upload: [folder=",folderitemid,", filename=",filename,"\n")
|
|
cat("Uploading...\n")
|
|
reqUpload<<-paste(storagehubEP,"/items/",folderitemid,"/create/FILE?gcube-token=",token,sep="");
|
|
|
|
print(reqUpload)
|
|
res<-POST(reqUpload,
|
|
body=list(name=filename, description=descr, file=upload_file(localfilename)),
|
|
add_headers("Content-Type" = "multipart/form-data"),
|
|
verbose())
|
|
print(res)
|
|
cat("All done.\n")
|
|
|
|
}
|
|
|
|
|