AnsweredAssumed Answered

Add Aspects, Aspect Value along with Upload File using REST

Question asked by poringe on Jan 8, 2015
Latest reply on Jan 17, 2017 by janaka1984
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

Outcomes