问题
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