使用R将CSV文件上传到REST API [英] Upload csv file to REST API with R
问题描述
我想将一个csv文件上传到REST API. 可通过
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
提供的示例curl调用如下:
A provided sample curl call looks as following:
curl --form "file=@my_data.zip" \
"http://sampledomain.com/api/data/?key=xxx"
如何将此调用转换为R? 我听说过RCurl软件包,但无法弄清楚在这种情况下如何使用它.
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.
致谢
推荐答案
I am not sure RCurl will handle it as you can see from the limit on the first page.
限制人们尚未完全控制a的内容 POST形式,例如指定文件,内容类型.错误处理用途 目前只有一个全局变量.
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.
但是,Hadley的另一个软件包可能会解决您的问题 httr
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"))))
这篇关于使用R将CSV文件上传到REST API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!