在R中上传超过2.15 GB的文件

Zac*_*ach 36 curl r rcurl httr

我有一个手动过程,我通过curl将5-6 GB文件上传到Web服务器:

curl -X POST --data-binary @myfile.csv http://myserver::port/path/to/api
Run Code Online (Sandbox Code Playgroud)

这个过程很好,但是我喜欢用R自动化它.问题是,我要么不知道我在做什么,要么curl的R库不知道如何处理大于~2GB的文件:

library(RCurl)
postForm(
     "http://myserver::port/path/to/api",
      file = fileUpload(
        filename = path.expand("myfile.csv"),
        contentType = "text/csv"
      ),.encoding="utf-8")
Run Code Online (Sandbox Code Playgroud)

Yeilds Error: Internal Server Error

httr也不起作用:

library(httr)
POST(
      url = "http://myserver:port/path/to/api",
      body = upload_file(
        path =  path.expand("myfile.csv"),
        type = 'text/csv'),
      verbose()
    )
Run Code Online (Sandbox Code Playgroud)

产量:

Response [http://myserver:port/path/to/api]
  Date: 2015-06-30 11:11
  Status: 400
  Content-Type: <unknown>
<EMPTY BODY>
Run Code Online (Sandbox Code Playgroud)

httr对该verbose()选项提供了更多信息,告诉我:

-> POST http://myserver:port/path/to/api
-> User-Agent: libcurl/7.35.0 r-curl/0.9 httr/1.0.0
-> Host: http://myserver::port
-> Accept-Encoding: gzip, deflate
-> Accept: application/json, text/xml, application/xml, */*
-> Content-Type: text/csv
-> Content-Length: -2147483648
-> Expect: 100-continue
-> 
<- HTTP/1.1 400 Bad Request
<- Server: Apache-Coyote/1.1
<- Transfer-Encoding: chunked
<- Date: Tue, 30 Jun 2015 11:11:11 GMT
<- Connection: close
<- 
Run Code Online (Sandbox Code Playgroud)

Content-Length: -2147483648看上去非常像一个32位的整数溢出,所以我觉得这是一个HTTR错误.我怀疑RCurl正在经历类似的失败.

我真的很喜欢一个最小的包装器curl -X POST --data-binary,但除此之外,我有什么选择从R上传相当大的文件?

Zac*_*ach 13

这个bug在httr/curl的dev版本中得到修复:

devtools::install_github("jeroenooms/curl")
devtools::install_github("hadley/httr")
Run Code Online (Sandbox Code Playgroud)

这是R 的httrcurl包中的一个错误.该错误已于2015年7月2日在GitHub上修复,并且该更改将很快推出到CRAN.

我也可能在上面的命令中错误地调用RCurl,但我永远无法弄清楚正确的调用.

  • __如果你实际上复制粘贴了上面的命令,你错误输入**uft-8**,它的**utf-8** (2认同)