upload file to issue using workfront api - Java

730 Views Asked by At

I am trying to upload a file to an issue under a project[Workfront] using Java Client to consume REST API's.

https://github.com/Workfront/api-bootcamp/blob/master/src/com/workfront/api/StreamClient.java

Above api-bootcamp has a client to upload a file( upload(File file) and upload(String url)).

But how do I attach a file to a particular issue/project and upload a file in Java?

        Map<String, Object> map = new HashMap<String, Object>();
        map.clear();
        map.put("projectID", "XXXXXXXX");
        JSONObject jb = client.upload(f); ??

         //TODO : How do I use client to upload a file. I am getting 
         illegalargument exception


        System.out.println(""+ jb);
2

There are 2 best solutions below

0
On

Attaching files to projects in Workfront is a two-step process. First, you must upload the file. I'm not familiar with the 3rd party API you're using, but I'm assuming that you don't have any issues with the actual file upload.

When you upload a file, you are given its UUID. Take that UUID and POST it to /attask/api/document?updates={name:<filename>,handle:<uuid>,docObjCode:TASK,objID:<task UUID>,currentVersion:{version:v1.0,fileName:<filename>}}

0
On

Thanks Guys. I was able to resolve this.

        File f = new File("Filename");
        Map<String, Object> map = new HashMap<String, Object>();

        JSONObject jb = client.upload(f); - Gives Handle

        map.put("name", "file name");
        map.put("handle", jb.get("handle"));
        map.put("docObjCode", "PROJ");
        map.put("objID", "XXXXXXXXXXXX");
        client.post("document", map); - uploads file