Search code examples
ibm-connections

ibm connections assigning file to folder


I have a problem when I try to assign a file with folder, the file and folder exist in the system but when I use the method for upload the folder of the file the response it's success but the file not figure into the folder.

I use the method

POST /basic/api/collection/{collection-id}/feed

in the collection-id I change for the folder UUID but don't works.

you know how assign a file to folder?

System.out.println("Uploading " + fileName + " in " + parentFolderName);
            Abdera abdera = new Abdera();
            Factory factory = abdera.getFactory();
            Entry entry = factory.newEntry();

        //Entry
            entry.setTitle(parentFolderName);
            entry.setId(parentFolderUUID);

            InputStream in = req.getInputStream();
            entry.setContent("application/pdf");
            entry.setLanguage("en");

            AbderaClient abderaClient = new AbderaClient(abdera);
            abderaClient.addCredentials(Utils.configJson.getString("connectionsServerURL"), null, null, new UsernamePasswordCredentials(connectionsUser, connectionsPassword));

        //Nonce
            String nonceUrl = "https://connectionsww.demos.ibm.com/files/basic/api/nonce";
            ClientResponse respNonce = abderaClient.get(nonceUrl);
            StringWriter writerNonce = new StringWriter();
            IOUtils.copy(respNonce.getInputStream(), writerNonce, "UTF-8");
            String nonce = writerNonce.toString();


        //Multipart-post options 
            RequestOptions options = abderaClient.getDefaultRequestOptions();
            options.setSlug(parentFolderUUID);
            options.setContentType("multipart/mixed");
            options.setAcceptLanguage("en");

            options.setHeader("X-Update-Nonce", nonce);
            fileURL = fileURL + "?X-Update-Nonce=" + nonce;


            ClientResponse resp = abderaClient.post(fileURL, entry);

Solution

  • based on the method signature, I think you are missing two items:

    One Content-Type header should be

    Content-Type: application/atom+xml
    

    Two payload of itemid (the id there is the id of the file I want in the folder/collection).

    <feed xmlns="http://www.w3.org/2005/Atom">
    <entry>
    <itemId xmlns="urn:ibm.com/td">aca70bd1-0925-42c1-8196-b1c3042178a6</itemId>
    </entry>
    </feed>