【问题标题】:Specify filename when using httr to POST file in R在 R 中使用 httr POST 文件时指定文件名
【发布时间】:2015-12-09 21:54:44
【问题描述】:

尝试使用 httr POST 从 R 上传数据文件。以下几乎可以工作,但我需要指定文件名,例如"mydata.csv"。如何指定文件名?到达服务器时为空白。

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

curl 中,可以使用-F name=filename 指定它,如:

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)

【问题讨论】:

    标签: r post httr


    【解决方案1】:

    -F 标志允许您通过 POST 传递其他表单值。您可以使用 httr 做到这一点,只需将更多命名元素添加到正文列表。

    POST("http://example.org/upload", body=list(name="test.csv", filedata=upload_file(filename, "text/csv")))
    

    【讨论】:

    • 太棒了。如果你想发送 3 个附件?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-30
    • 1970-01-01
    • 1970-01-01
    • 2018-07-27
    • 2021-12-21
    • 1970-01-01
    相关资源
    最近更新 更多