POST image via plumber

I'm stuck trying to enable uploading an image to a Plumber API for use in a workflow. Something like this:

#* Plot a histogram
#* @param image:file
#* @post /test_image_upload
function(image) {
  magick:image_read(image)
}

I've looked here: Swaggerfile support for array parameters, object, files by meztez · Pull Request #532 · rstudio/plumber · GitHub</title and here Upload multiple file through plumber API in R but can't make sense on how to parse the image once it is sent via Plumber.

Can't find any examples of this.

Sometimes it helps to use a browser() to see what you are working with.

#* Plot a histogram

#* @param image:file

#* @post /test_image_upload

function(image) {
  browser()
  magick:image_read(image)
  
}

From this, we can see that image is a list of length one. The first element in the list is a raw vector containing the uploaded file in binary form.

From there you can use

library(magick)

#* Plot a picture
#* @param image:file
#* @post /test_image_upload
function(image) {
  image_read(image[[1]])
  # processing
  "done"
}

There is an example here Annotations reference • plumber of working with files.

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.