AnsweredAssumed Answered

Upload File in User Authenticated Web Script

Question asked by scoppola on Sep 20, 2010
Latest reply on Apr 11, 2011 by segzy
Hi all,
i'm trying to upload a file with http client to my WebScript configured as authenticated by user (so alf_ticket).
My problem is parameters sending through http client, it seem the code is correct, any help?
I user Apache Http Client to do call to alfresco web script

   public static String doUploadCall(String ticket, Map<String, Object>  parameters, UploadFile file, String url)throws HttpException, IOException{
         HttpClient client = new HttpClient();
      
         PostMethod method = new PostMethod(url);     
        
         method.getParams().setBooleanParameter(HttpMethodParams.USE_EXPECT_CONTINUE, true);
        
         JSONObject json = JSONObject.fromObject(parameters);
      
         File f = new File("temp");
         OutputStream output = new FileOutputStream(f);
         IOUtils.copy(file.getInpuStream(), output);
      
        
         Part[] parts = {
               new StringPart("alf_ticket", ticket),
               new StringPart("parameters", json.toString()),
               new FilePart(file.getFileName(), f)
         };
        
         method.setRequestEntity(
               new MultipartRequestEntity(parts, method.getParams())
      );
         
         int statusCode = client.executeMethod(method);
         if (statusCode != HttpStatus.SC_OK) {
        System.err.println("Method failed: " + method.getStatusLine());
         }
         return method.getResponseBodyAsString();
   }

Outcomes