使用Desire2Learn的REST API上传到我个人Locker中的文件夹

时间:2012-04-27 16:25:05

标签: desire2learn

如何使用Desire2Learn的REST API将文件上传到我的储物柜?服务器返回状态代码200,但“发生意外错误”

POST /d2l/api/le/1.0/locker/mylocker/?x_a={appID}&x_c={appSig}&x_b={myUserID}&x_d={myUserSig}&x_t={time) HTTP/1.1
Host: myHost.com
Accept: */*
Content-type: multipart/mixed;boundary=BOUNDARY
Content-Length: 181

--BOUNDARY
Content-Type: text/plain
Content-Length: 4

test
--BOUNDARY
Content-type: application/json
Content-Length: 36

{"Description":"","IsPublic":"true"}
--BOUNDARY--

编辑(另一个请求,同样的结果)

POST /d2l/api/le/1.0/locker/mylocker/testFile?{authQueryparms}
Host: myHost.com
Accept: */*
Content-type: multipart/mixed;boundary=BOUNDARY
Content-Length: 288

--BOUNDARY
Content-Type: text/plain
Content-Length: 4

test
--BOUNDARY
Content-type: application/json
Content-Length: 142

{ "Description": {"Text": "Text description string for file.", "HTML": "<p>Text description string for <i>file</i>.</p>" }, "IsPublic": true }
--BOUNDARY--

1 个答案:

答案 0 :(得分:0)

(好的,让我们再试一次)

原始问题的问题似乎是后端服务不知道要为您上传的文件提供什么文件名,而不是它在哪里放置它有问题(它会尝试放入它在你的储物柜的根文件夹中)。请求中的文件上传部分必须具有提供文件名的 Content-Disposition 标头。以下是我们已确认在我们的测试服务器上运行的示例请求:

POST http://test.host/d2l/api/le/1.0/locker/mylocker/?{authQueryPams} HTTP/1.1
Content-Type: multipart/mixed; boundary=8cefca62f73c56c
Host: test.host
Content-Length: 595514

--8cefca62f73c56c
Content-Type: application/json

{"Description":"Test","IsPublic":false}
--8cefca62f73c56c
Content-Disposition: form-data; name=""; filename="test.jpg"
Content-Type: image/jpeg

<binary data>
--8cefca62f73c56c--