232 upload file to folder#233
Conversation
| case 0 => BadRequest("No files uploaded") | ||
| case 1 => Ok(Json.obj("id" -> uploadedFiles.head.id)) | ||
| case _ => Ok(Json.obj("ids" -> uploadedFiles.toList)) | ||
| folder_id match { |
There was a problem hiding this comment.
I think we can simplify (not tested)
val folder = folder_id.flatmap(x => folders.get(x))
val uploadedFiles = FileUtils.uploadFilesMultipart(request, Some(dataset), folder, showPreviews = showPreviews, originalZipFile = originalZipFile, flagsFromPrevious = flagsFromPrevious, runExtractors = extract, apiKey = request.apiKey)
uploadedFiles.length match {
case 0 => BadRequest("No files uploaded")
case 1 => Ok(Json.obj("id" -> uploadedFiles.head.id))
case _ => Ok(Json.obj("ids" -> uploadedFiles.toList))
}
This will use flatmap (if there is a value, return an option) to get the folder and then just call the next function with ether None, or Some(folder).
There was a problem hiding this comment.
I am using the flatmap.
This works if folder_id is a UUID, and it works if folder_id is None, however, it breaks if folder_id is a string but not a UUID.
I know that there is a way to use conditionals inside of a flatMap, so I am trying to figure that out. Unless you know a quick fix offhand.
There was a problem hiding this comment.
I am now using a conditional that seems to handle all cases without breaking.
Regrettably it kept giving me an error if I tried to put an Option[UUID] in the api route and didn't send it, but this seems to match what is done in a few other cases with optional uuid parameters.
lmarini
left a comment
There was a problem hiding this comment.
(This PR is not urgent, it can go in the next release) There is one issue mentioned below. Can you also please updated the changelog? Thank you!
| datasets.get(dataset_id) match { | ||
| case Some(dataset) => { | ||
| val uploadedFiles = FileUtils.uploadFilesMultipart(request, Some(dataset), showPreviews = showPreviews, originalZipFile = originalZipFile, flagsFromPrevious = flagsFromPrevious, runExtractors = extract, apiKey = request.apiKey) | ||
| val current_folder = if (UUID.isValid(folder_id.get)){ |
There was a problem hiding this comment.
This throws an error if folder == None
There was a problem hiding this comment.
I believe I have fixed this. Also updated changelog
This pull request enabled users to upload files to a folder in a dataset through the api. Previously this option was not available.
The route api.Files.uploadToDataset now has a parameter folder_id: Option[String].
Swagger documentation for that route has also been updated.