【发布时间】:2015-06-30 20:38:04
【问题描述】:
我有一个手动过程,我通过 curl 将 5-6 GB 文件上传到网络服务器:
curl -X POST --data-binary @myfile.csv http://myserver::port/path/to/api
这个过程运行良好,但我很想使用 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")
产量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()
)
产量:
Response [http://myserver:port/path/to/api]
Date: 2015-06-30 11:11
Status: 400
Content-Type: <unknown>
<EMPTY BODY>
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
<-
Content-Length: -2147483648 看起来有点像 32 位整数溢出,所以我认为这是 httr 中的错误。我怀疑 RCurl 遇到了类似的故障。
我真的很喜欢 curl -X POST --data-binary 的最小包装器,但除此之外,我有哪些选择可以从 R 上传相当大的文件?
【问题讨论】:
-
我假设您使用的是最新版本的 httr,它使用的是 curl R 包。如果您无法直接使用 Jeroen 的包(绕过 httr)使其工作,那么在 github 上创建问题可能会更快。
-
@joran 是的,我正在使用 httr,这取决于 curl。我提出了一个 github 问题,但与此同时,我很想知道是否有人每次都从 R 上传一个 2.2GB 以上的文件到网络服务。我不能成为历史上第一个尝试这样做的人......
-
在此期间,您可能可以使用
system直接调用curl。 -
@tonytonov 好主意,我现在就试试。
-
@costebk08 我不认为 RevoScaleR 包含 curl 的替代品。