【发布时间】:2015-03-28 01:07:23
【问题描述】:
我正在尝试使用 Scribe 使用他们的 V3 API(使用 Java,在 Google App Engine 中)将 GPX 文件(未压缩)上传到 Strava:
String url = "https://www.strava.com/api/v3/uploads?access_token=<TOKEN>";
OAuthRequest req = new OAuthRequest(Verb.POST, url);
req.addQuerystringParameter("private", "1");
req.addQuerystringParameter("activity_type", "bike");
req.addQuerystringParameter("data_type", "gpx");
req.addQuerystringParameter("external_id", <Unique String>);
req.addHeader("Content-Type", "multipart/form-data");
String gpx = <Content of GPX file to Upload>;
req.addBodyParameter("file", gpx);
Response response = request.send();
结果是我从 Strava 收到响应代码 500(内部错误),并且它没有上传 GPX 活动。
我想这是我如何形成 HTTP 多部分 POST 的问题,它在 Strava 文档here 中定义为:
DEFINITION
POST https://www.strava.com/api/v3/uploads
EXAMPLE REQUEST
$ curl -X POST https://www.strava.com/api/v3/uploads \
-F access_token=83ebeabdec09f6670863766f792ead24d61fe3f9 \
-F activity_type=ride \
-F file=@test.fit \
-F data_type=fit
Parameters:
<OTHERS>
file: multipart/form-data required
the actual activity data, if gzipped the data_type must end with .gz
请问有什么想法可以让我完成这项工作吗?谢谢。
编辑:通过我自己的进一步调查发现了几件事:
- Scribe 主要是为了签署 oauth,所以作者并不专注于添加处理多部分/表单数据的功能(尽管有人建议添加此类功能)
- 我可以通过 Scribe 使用其中一个 Apache 类 (MultipartEntity) 来执行此操作,但我认为 Google App Engine 不支持 Apache 库。见this线程,这将是完美的,除了Apache / GAE问题
【问题讨论】:
标签: java google-app-engine scribe