0

我使用 Alfresco Cloud,我想在指定的文件夹中创建一个文件(例如文本文件)。

文档真的很差,我想知道是否有人知道如何做到这一点。我只知道我必须使用 POST 请求,但不知道查询的参数......

谢谢。

4

1 回答 1

0

我解决了这个问题:

        String accessToken = "your access token"
        String filename = "FileName";
        String filesummary = "Test file summary";
        String filecontent = "Hello world!";
        String filetype = "text/plain";

        String body = "<?xml version=\"1.0\" encoding=\"utf-8\"?><entry xmlns=\"http://www.w3.org/2005/Atom\" xmlns:cmisra=\"http://docs.oasis-open.org/ns/cmis/restatom/200908/\" xmlns:cmis=\"http://docs.oasis-open.org/ns/cmis/core/200908/\">" 
                    + "<title>" + filename + "</title> " 
                    + "<summary>" + filesummary +"</summary>"
                    + "<content type=\"" + filetype + "\">" + filecontent + "</content>"
                    + "<cmisra:object> <cmis:properties> <cmis:propertyId propertyDefinitionId=\"cmis:objectTypeId\"><cmis:value>cmis:document</cmis:value></cmis:propertyId> </cmis:properties> </cmisra:object> </entry>";

        byte[] content = Encoding.UTF8.GetBytes(body);
        HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create("https://api.alfresco.com/yoursite.com/public/cmis/versions/1.0/atom/children?id=your_folder_id");
        req.Method = "POST";
        req.Headers.Add("Authorization", "Bearer " + accessToken);

        req.ContentType = "application/atom+xml; charset=UTF-8"; 
        req.ContentLength = content.Length;
        using (Stream stream = req.GetRequestStream())
        {
            stream.Write(content, 0, content.Length);
        }

        HttpWebResponse webResponse = (HttpWebResponse)req.GetResponse();
        StreamReader sr = new StreamReader(webResponse.GetResponseStream());
        String responseContent = sr.ReadToEnd();
        MessageBox.Show(responseContent);
于 2013-09-23T12:24:56.463 回答