3

Trying to upload a datafile from R using httr POST. The following almost works but I need to specify the filename, e.g. "mydata.csv". How do I specify the filename? It's blank when it reaches the server.

POST(uri, body=list(y=upload_file(filename)))

In curl one would specify it with a -F name=filename as in :

curl -i -F name=test -F filedata=@localfile.jpg http://example.org/upload

How to POST multipart/related content with httr (for Google Drive API)

Community
  • 1
  • 1
prototype
  • 7,249
  • 15
  • 60
  • 94

1 Answers1

7

The -F flag allows you to pass additional form values with your POST. You can do that with httr by just adding more named elements to the body list.

POST("http://example.org/upload", body=list(name="test.csv", filedata=upload_file(filename, "text/csv")))
prototype
  • 7,249
  • 15
  • 60
  • 94
MrFlick
  • 195,160
  • 17
  • 277
  • 295