Search code examples
rrestshinyuploadxlsx

Saving .xlsx file to disc, form http post request


I have a Plumber rest api, where i have a post request, that sends an excel file

when i access the request object like this

this is the attributes i get:

formContents <- Rook::Multipart$parse(req)
formContents$upload

this is what i get

["app_x_browser.xlsx","/tmp/RtmpWOKV2O/Multipart1d3261d35443","application/octet-stream","Content-Disposition: form-data; name=\"upload\"; filename=\"app_x_browser.xlsx\"\r\nContent-Type: application/octet-stream"]

how can i save this response on disc, from this json data? is there anyway to extract the data and save it onto a file?


Solution

  • I think you could try to send your xlsx file in raw format with something like this in your plummer file

    xlsx <- "path/to/xlsxfile.xlsx"
    readBin(xlsx, "raw", n=file.info(xlsx)$size)
    

    then of course you will need to handle this with your api request

    [your call to the api] > results.xlsx
    

    hope this helps