package com.kristall; import java.io.File; import java.io.IOException; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.auth.AuthScope; import org.apache.commons.httpclient.methods.PostMethod; import org.apache.commons.httpclient.methods.multipart.FilePart; import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity; import org.apache.commons.httpclient.methods.multipart.Part; import org.apache.commons.httpclient.methods.multipart.StringPart; import org.apache.commons.httpclient.Credentials; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpException; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.UsernamePasswordCredentials; import org.apache.commons.httpclient.methods.GetMethod; /** * @author aaa * */ public class FileUpload { public static void uploadDocument(String authTicket, File fileobj,String filename, String filetype, String description,String destination) { try { // String urlString = "http://10.10.12.116:8080/alfresco/service/api/upload?alf_ticket="+ authTicket; String urlString = "http://10.10.12.116/alfresco/service/api/upload?alf_ticket="+ authTicket; System.out.println("The upload url:::" + urlString); HttpClient client = new HttpClient(); PostMethod mPost = new PostMethod(urlString); //File f1 =fileobj; Part[] parts = { new FilePart("filedata", filename, fileobj, filetype, null), new StringPart("filename", filename), new StringPart("description", description), //new StringPart("destination", destination), new StringPart("description", description), //modify this according to where you wanna put your content new StringPart("siteid", "test"), new StringPart("containerid", "documentLibrary"), //new StringPart("uploaddirectory", "/Company Home") }; mPost.setRequestEntity(new MultipartRequestEntity(parts, mPost.getParams())); int statusCode1 = client.executeMethod(mPost); System.out.println("statusLine>>>" + statusCode1 + "......"+ "\n status line \n"+mPost.getStatusLine() + "\nbody \n" +mPost.getResponseBodyAsString()); mPost.releaseConnection(); } catch (Exception e) { System.out.println(e); } } public static void main(String args[]) throws IOException { // SimpleUpload aw=new SimpleUpload(); // String Ticket=aw.login(); // String ticket="TICKET_3e61ccfa8a11690b10e1a2fb0eeee2c5583b0043"; // aritz : not using predefined method to get credential //String alfrescoTiccketURL = "http://192.168.100.152:8080/alfresco"+ "/service/api/login?u=" + "admin" + "&pw=" + "admin"; // String alfrescoTiccketURL = "http://10.10.12.116:8080/alfresco"+ "/service/api/login?u=" + "boltaev" + "&pw=" + "boltaev"; String alfrescoTiccketURL = "http://10.10.12.116/alfresco"+ "/service/api/login?u=" + "boltaev" + "&pw=" + "boltaev"; InteractiveAuthentication ticket = new InteractiveAuthentication(); String ticketURLResponse = ticket.getTicket(alfrescoTiccketURL); File f = new File("/home/oleg/test.pdf"); // FileInputStream is=new FileInputStream(f); uploadDocument(ticketURLResponse, f, "test.pdf","application/pdf", "description", null); // uploadDocument("TICKET_3ef085c4e24f4e2c53a3fa72b3111e55ee6f0543",f,"47.bmp","image file","application/jpg","workspace://SpacesStore/65a06f8c-0b35-4dae-9835-e38414a99bc1"); //workspace://SpacesStore/88662918-1a1a-40cc-a0a1-8907a9d5d6fd } }