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 as described in 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:

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

Hello World

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)
          new MultipartRequestEntity(parts, filePost.getParams())
      client = new HttpClient();
      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

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