desire2learn - 404 Error when trying to post a file topic -
i trying create content in d2l orgunit keep getting 404 page not found back. calling android emulator. i've created module topic link using post apis. did @ post 404 posting content desire2learn helped me module , link working, can't uploading file topic work. suspect may url wasn't sure put, put relative path created in org unit. post 404 posting content desire2learn mentions use "valid location url within org unit's existing content space". tried /content/enforced/... folder url no avail. i'm not sure if issue, or red herring...
here code:
string body = "--xxboundaryxx " + "content-type: application/json " + "{" + "\"title\": \"testing upload\"," + "\"shorttitle\": \"test\"," + "\"type\": 1," + "\"topictype\": 1," + "\"url\": \"/test/\"," + "\"startdate\": null," + "\"enddate\": null," + "\"ishidden\": false," + "\"islocked\": false" + " } " + "--xxboundaryxx " + "content-disposition: form-data; name=\"file 0\"; filename=\"test.txt\" " + "content-type: text/plain " + "this sample file try out."; uri uri = usercontext.createauthenticateduri("/d2l/api/le/1.1/{orgid}/content/modules/{moduleid}/structure/", "post"); defaulthttpclient httpclient = new defaulthttpclient(); httppost post = new httppost(uri); post.addheader("content-type", "multipart/mixed; boundary=xxboundaryxx"); post.setentity(new stringentity(body)); httpresponse response = httpclient.execute(post); log.i(tag, "statusline: " + response.getstatusline());
here resulting body (i put \r\n line breaks well, didn't help).
--xxboundaryxx content-type: application/json { "title": "testing upload", "shorttitle": "test", "type": 1, "topictype": 1, "url": "/test/", "startdate": null, "enddate": null, "ishidden": false, "islocked": false } --xxboundaryxx content-disposition: form-data; name="file 0"; filename="test.txt" content-type: text/plain sample file try out.
what going on? getstatusline returns 404 error... know not permission issue since can create modules , link topics using similar code. guidance appreciated.
you need terminating boundary on post body (--xxboundaryxx--
). url
property in json block send: can send url that's not relative (as in example in docs); seems can send file name (relative name) , upload process puts file in root of course's content area. expect (a) if don't have absolute url, use course's root folder base part of path, , (b) upload api action not create directories you, haven't comprehensive testing around how url
property gets handled.
i've tested api action on our test servers, , works (with specified url
, file name url
). i've updated valence docs include concrete example of course content file topic upload packet: hope these 2 things out.
Comments
Post a Comment