1

如何使用 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--
4

1 回答 1

0

(OK, let's try this again)

It seems that the issue with your original question is that the back-end service doesn't know what file name to give to your uploaded file, not that it has a problem with where to put it (it will attempt to put it in your locker's root folder). The file-upload part in your request has to have a Content-Disposition header that provides the filename. Here's an example request that we've confirmed works on our test servers:

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--
于 2012-04-27T17:15:33.103 回答