Hi there,
I would like to create a raster from a POST request in plumber API.
After making a POST request with a given raster in body and this POST request reported a status_code = 200. I would like to re-create the raster in the content of the POST request, but I am finding many problems in doing so.
Is there anyone who has experience with this who can help me?
This is the r code that allow to build up the endpoint of the API
while the following is the code that i am using to make the POST request and the functions that i am using to rebuild the raster passed to the POST request
library(httr)
api_url <- "http://localhost:4867/prediction"
r <- httr::POST(
api_url,
body=list(raster=upload_file(".../red_raster.tif"))
)
httr::status_code(r)
bin_raster<-readBin(r$content, what = "raw", n=length(r$content))
writeBin(bin_raster, con = "raster.tif")
r <- raster::raster("raster.tif")
mapview::mapview(r)
Also using this code the reconstructed raster does not have a crs
You are using an image serializer, you might want to use a plot output? Do you want to return a plot representing the content of the original tiff file OR the original tiff file content. The first one would be the a saved plot in tiff format, the second would the actual tiff source.
raster::plot(r)
Instead of return(r)
Otherwise, you would use an octet serializer, probably with as_attachment