AnsweredAssumed Answered

File Upload Error

Question asked by dryok on Jan 30, 2010
Latest reply on Jan 30, 2010 by dryok
Hi.

I'm new using Alfresco, and I need to upload a file whith Java.

First, I have tried using Web Service and it's works fine, but when i try to upload files whith size of 2.5 MB or more I receive an axis Java Heap Space error. I get that error too with slower size files if I launch some uploads concurrently.

Now I'm trying to upload using the RestApi. I use the Web Script /alfresco/service/api/upload but i'm receiving an error 500(Internal Error):An error inside the HTTP server which prevented it from fulfilling the request.

I tried using a simple HTML form as indicates the Web Script description in /alfresco/service/index/all:
File Upload
POST /alfresco/service/api/upload

Upload file content and meta-data into repository.
HTML form data

    * filedata, (mandatory) HTML type file
    * siteid
    * containerid
    * uploaddirectory
    * updatenoderef
    * filename
    * description
    * contenttype
    * majorversion
    * overwrite
    * thumbnails

So I created the follow HTML form:
<html>
   <body>
      <form method="post" action="http://localhost:8080/alfresco/service/api/upload?alf_ticket=TICKET_405f319152813bc46da98266b83777cf2a7c4eba" >
         <input type="file" name="filedata" />
         <input type="hidden" name="description" value="a description" />
         <input type="hidden" name="filename" value="myFile" />
         <input type="hidden" name="containerid" value="af05cb2c-8100-442c-8dce-de81a8de57b0"/>
         <input type="submit" name="submit" value="upload" />
      </form>
   </body>
</html>

But when i submit it I get the error An error inside the HTTP server which prevented it from fulfilling the request.


I tried using Java, and I code the follow:
        // Instancite object
        DefaultHttpClient httpClient = new DefaultHttpClient();
       
        // Set Authentication
        if(USE_CREDENTIALS) {
            Credentials credentials = new UsernamePasswordCredentials(LOGIN, PWD); 
            CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
            credentialsProvider.setCredentials(AuthScope.ANY, credentials);
            httpClient.setCredentialsProvider(credentialsProvider);
        }
        else if(USE_TICKET) {
            URL = URL + "?alf_ticket=" + TICKET;
        }
       
        // Use Post
        HttpPost request = new HttpPost(URL);

        // Read Server Response
        HttpResponse response = httpClient.execute(request); 
      
       // Checking response…
       if( response.getStatusLine().getStatusCode() == 200 ) {
           String json = getJSon(response.getEntity().getContent());
           System.out.println("JSON received: " + json);
       }
       else {
           System.err.println("Upload Failed: \n"
               + response.getStatusLine().getStatusCode() + " : " + response.getStatusLine().getReasonPhrase() + "\n"
               + getJSon(response.getEntity().getContent()) );
       }

But I get the same error.

Any idea about why I get that error and how I can solve it ?

Thx 4 hlp !

Outcomes