Upload csv file to REST API with R

こ雲淡風輕ζ 提交于 2020-01-15 19:31:27

问题


I want to upload a csv file to a REST API. The API is accessible via an URL like

http://sampledomain.com/api/data/?key=xxx

A provided sample curl call looks as following:

 curl --form "file=@my_data.zip" \
     "http://sampledomain.com/api/data/?key=xxx"

How can I translate this call into R? I heard of the RCurl package, but can´t figure out how to use it in this case.

Regards


回答1:


I am not sure RCurl will handle it as you can see from the limit on the first page.

Limitations One doesn't yet have full control over the contents of a POST form such as specifying files, content type. Error handling uses a single global variable at present.

However, another package from Hadley that might solve your problem httr

POST("http://sampledomain.com/api/data/?key=xxx", body = list(y = upload_file(system.file("my_data.zip"))))


来源:https://stackoverflow.com/questions/25733571/upload-csv-file-to-rest-api-with-r

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!