cancel
Showing results for 
Search instead for 
Did you mean: 

Add Aspects, Aspect Value along with Upload File using REST

poringe
Champ in-the-making
Champ in-the-making
Hi,

i want to add 'aspects' and 'aspects value' along with 'upload file' in 1 REST request

public String uploadDocument(File fileobj, List<PropertiesModel> metaData)         throws Exception {      String ticketURLResponse = getTicket();      String urlString = "http://" + inboundServerIp + ":"            + inboundServerPort            + "/alfresco/service/api/upload?alf_ticket="            + ticketURLResponse;      HttpClient client = new HttpClient();      PostMethod mPost = new PostMethod(urlString);      BufferedReader br = null;      try {         Part[] parts = {               new FilePart("filedata", fileobj, "application/pdf", null),               new StringPart("filename", fileobj.getName()),               new StringPart("destination", "workspace://SpacesStore/"                     + folderUUID),               new StringPart("aspects",                     "PolicyNumber:PolicyNumber,ReferenceNumber:ReferenceNumber") };         mPost.setRequestEntity(new MultipartRequestEntity(parts, mPost               .getParams()));         int statusCode1 = client.executeMethod(mPost);         if (statusCode1 != 200) {            throw new Exception("Error!" + mPost.getResponseBodyAsString());         } else {            br = new BufferedReader(new InputStreamReader(                  mPost.getResponseBodyAsStream()));            String readLine;            while (((readLine = br.readLine()) != null)) {               if (readLine.contains("workspace://SpacesStore/")) {                  break;               }            }            int startindex = readLine.indexOf("workspace://SpacesStore/")                  + "workspace://SpacesStore/".length();            int endindex = readLine.indexOf("workspace://SpacesStore/")                  + "workspace://SpacesStore/".length() + 36;            String uuid = readLine.substring(startindex, endindex);            return uuid;         }      } catch (Exception e) {         throw e;      } finally {         if (br != null) {            br.close();         }         mPost.releaseConnection();      }   }‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍


file is uploaded, aspects is added but how can i add value to aspect? (PolicyNumber, ReferenceNumber)

Sorry for my english
1 REPLY 1

janaka1984
Star Contributor
Star Contributor

how can you solve this issue?