Problem with data size when using POST from httr package

Hi,

I want to use POST to upload an rtf (rich text format) file to a documentation system in the company I work for. There is a nice OData interface, and a Swagger explaining how to do it. When I test the uploading from the Swagger docs everything works just fine.

Now I try to do the upload from R (in the end it will become a Shiny app), and I use POST command from the httr package. It all works fine when the data I'm POSTing is not too large, but with large data (for example when I have jpegs embedded in the rtf) POST fails. Spuriosly, it fails with error "401 - Unauthorized: Access is denied due to invalid credentials". As a test, if I reduced the jpeg just slightly (the reduction is 2x2 pixels) the POST works just fine. I have stepped through all the httr code using debug(POST), but haven't found any clues.

The limit where the POST fails is suspiciously close to 65536 bytes.

Is anybody aware of any limitations to the size of the data field in POST? Google haven't helped, and neither has browsing the source code a Github for curl or httr.

As this is all in-house proprietary systems I cannot make a reprex. However, the code for POST call is this:

# the rtf formatted text and jpeg is in the rtfstring variable
# postlist contains the json formatted data for the OData API, where the rtf field contains the rtf encoded text
postlist = list(title="Entry30", rtf=rtfstring, externalId="string", readOnly=FALSE)
postdata = toJSON(postlist)
POST(url="http://OurLocalDocSystem/odata/CreateEntry", authenticate(":", "", "gssnegotiate"), content_type_json(), body=postdata, encode="raw")

Just for clarity, when the size of postdata is 65573 characters the POST call fails with error 401, but when postdata is 65309 characters it works fine with response status 200. And both options (as well as an example where postdata is well above 150000 characters) work well when I use the Swagger docs interface.

Session info:

R version 3.5.1 (2018-07-02)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

locale:
[1] LC_COLLATE=Danish_Denmark.1252  LC_CTYPE=Danish_Denmark.1252    LC_MONETARY=Danish_Denmark.1252 LC_NUMERIC=C                    LC_TIME=Danish_Denmark.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] curl_3.2       rjson_0.2.20   httr_1.3.1     readr_1.1.1    magrittr_1.5   ggplot2_3.0.0  reshape2_1.4.3 plyr_1.8.4    

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.18      pillar_1.3.0      compiler_3.5.1    bindr_0.1.1       R.methodsS3_1.8.1 tools_3.5.1       digest_0.6.15     jsonlite_1.5      tibble_1.4.2     
[10] gtable_0.2.0      pkgconfig_2.0.2   rlang_0.2.1       rstudioapi_0.7    yaml_2.2.0        bindrcpp_0.2.2    withr_2.1.2       dplyr_0.7.6       stringr_1.3.1    
[19] hms_0.4.2         grid_3.5.1        tidyselect_0.2.4  glue_1.3.0        R6_2.2.2          purrr_0.2.5       scales_1.0.0      assertthat_0.2.0  colorspace_1.3-2 
[28] labeling_0.3      stringi_1.1.7     lazyeval_0.2.1    munsell_0.5.0     crayon_1.3.4      R.oo_1.24.0      

Thanks
Steen

You could try to raise an issue here https://github.com/r-lib/httr/issues

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.