3

I tested to attach an STL file as body on a POST request. Configuration: Windows 10, Postman (POST->binary), R 3.4.2. The R code for the POST request looks like:

#' @post /endpointname
function(req) {
    rawstl = req$postBody  # STL file is attached as Binary in Postman.
    rawData1 = as.raw(unlist(lapply(rawstl, charToRaw)))
    ## E.g. 43 4f 4c 4f 52 3d ...
    ...
}

The output of this is the same as a direct binary read on the STL file using:

 con = file(fileName, "rb")
 rawData2 = readBin(con, "raw", n=100, size=1, endian="little")

however there are some parts missing if the Plumber version (above) is used. I think the reason could be the way line endings are handled or introduced, or Plumber's default filters.

The missing values occur between the elements of req$postBody: e.g. while rawData2 holds [a, b, c, d, e, f, g], rawData1 holds [a, b, e, f]. The R object rawstl in the function above has length > 1 and the missing values occur between the sub-lists there.

I played around for some time but I cannot figure out what is broken.

lambruscoAcido
  • 548
  • 4
  • 17
  • A reproducible example would be really helpful in tracking this down. – Jeff Allen Dec 18 '17 at 15:01
  • @JeffAllen you are right but it is a bit tricky to explain all the details. In the meanwhile I managed to put the data on a file server and instead of attaching them I access the file server from the Docker container. – lambruscoAcido Jan 10 '18 at 20:11
  • 1
    I'm having exactly this issue while trying to use Protocol Buffers. Did you find a solution since you posted this? – mariachi Feb 01 '19 at 15:32
  • @mariachi - no I did not find a solution so far. I used a workaround, but would be happy to have a working solution. – lambruscoAcido Feb 04 '19 at 10:11
  • @lambruscoAcido could you share your workaround? So far I've come up with nothing worth implementing. – mariachi Feb 04 '19 at 17:03
  • @mariachi in my case the REST API is on the same server as the file to be transmitted. So I simply attached the URL as a GET parameter and the service could access directly to the file. But I think usually this is definitely not a solution. – lambruscoAcido Feb 06 '19 at 07:09

0 Answers0