AnsweredAssumed Answered

Uploading using UploadContentServlet [Solved]

Question asked by ale_carraro on Aug 3, 2009
Latest reply on Aug 5, 2010 by kits
I'm trying to upload a file using org.alfresco.web.app.servlet.UploadContentServlet as described in
http://wiki.alfresco.com/wiki/URL_Addressability#UploadContentServlet. The upload is a success, but the content is not the one I planned to upload:

Uploading a text file containing
Hello World
results in a file containing:

–ntFc1CtoJLgJ94PK6EIn_3Dm8HX7nXBzL
Content-Disposition: form-data; name="test.txt"
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 8bit

Hello World
–ntFc1CtoJLgJ94PK6EIn_3Dm8HX7nXBzL–

The code I'm using (with the help of Apache HttpClient) is (the snippet actually updates an existing document)

public static void main(String[] args) {
    String fileName = args[0];
    String URL = "http://localhost:8080/alfresco/upload/workspace/SpacesStore/71ee6b00-c473-4fe1-be97-40bc5d6cf80f/";
    PutMethod filePost = null;
    HttpClient client = null;
    try {
      String ticket = getTicket();
      filePost = new PutMethod(URL+fileName+"?ticket="+ticket);
      File mFile = new File(fileName);
      FilePartSource fileSource = new FilePartSource(mFile);
      Part[] parts = {
          new FilePart(fileName, fileSource)
      };
      filePost.setRequestEntity(
          new MultipartRequestEntity(parts, filePost.getParams())
      );
      client = new HttpClient();
      client.getHttpConnectionManager().getParams().setConnectionTimeout(5000);
      int status = client.executeMethod(filePost);
      if (status == HttpStatus.SC_OK) {
        System.out.println("Upload success");
      } else {
        System.out.println("Upload failed: " + HttpStatus.getStatusText(status));
      }

Did I miss something important?
Thanks in advance
Alex

p.s. If you need the full code I may provide id as well

Outcomes