Skip to content
Snippets Groups Projects
Commit 7c785cac authored by LouisGendron's avatar LouisGendron
Browse files

Improved validation of 'annotation' parameter in file_upload function

parent dcd881e6
No related branches found
No related tags found
1 merge request!3Resolve "fetch files annotations when download dataset"
......@@ -178,6 +178,16 @@ setMethod(
f='file_upload',
signature='IRICData',
definition=function(object, session, file_path, annotation='', lab='', dataset=''){
#Check if annotation can be parsed as JSON
if (typeof(annotation) == 'list'){annotation <- toJSON(annotation)}
else if (typeof(annotation) == 'character'){
validation = jsonlite::validate(annotation)
if(!(validation[[1]])){
print(paste('Error occured while uploading', file_path,
': the annotation parameter could not be parsed as JSON'))
return(NULL)
}
}
file_form = list(file=httr::upload_file(file_path),
lab=lab, annotations=annotation, dataset=dataset)
......@@ -273,12 +283,12 @@ setMethod(
if (is.null(metas[ix][[1]])){
next
}else{
ds_details <- rbind(ds_details, data.table(file_name = metas[[ix]]$filename,
file_id = files_id[[ix]],
hash = metas[[ix]]$hash))
ds_details <- rbind(ds_details,
data.table(file_name = metas[[ix]]$filename,
file_id = files_id[[ix]],
hash = metas[[ix]]$hash))
}
}
return(ds_details)
}
)
......@@ -36,7 +36,7 @@ DL_file(IData, IData_session, file_id, "directory/output/path")
# To download a file annotations using file db_id or slug_id
DL_file_annotation(IData, IData_session, file_id, "directory/output/path")
# To upload a file
# To upload a file, annotation as a named list or JSON formated character.
file_upload(IData, IData_session, '/path/to/my/file.txt', annotation, lab, dataset)
# To get file metadata using file db_id or slud_id
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment