04-19-2015 07:09 PM
String urlString = "http://'+ipaddress+':8080/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("contenttype", "rs:invoiceDoc" ),
new StringPart("description", description),
new StringPart("rs:itemName","Item1,Item2"),
new StringPart("rs:vendor","sample vendor"),
// modify this according to where you wanna put your content
new StringPart("siteid", siteid),
new StringPart("containerid", "documentLibrary"),
// new StringPart("uploaddirectory", "/Company Home")
};
mPost.setRequestEntity(new MultipartRequestEntity(parts, mPost
.getParams()));
int statusCode1 = client.executeMethod(mPost);
new StringPart("rs:itemName","Item1,Item2")
05-02-2015 07:51 AM
05-04-2015 11:36 PM
String url = "http://localhost:8080/alfresco/api/-default-/public/cmis/versions/1.1/atom";
String userName = "kaynezhang";
String password = "kaynezhang";
SessionFactory sessionFactory = SessionFactoryImpl.newInstance();
Map<String, String> params = new HashMap<String, String>();
params.put(SessionParameter.USER, userName);
params.put(SessionParameter.PASSWORD, password);
params.put(SessionParameter.ATOMPUB_URL, url);
params.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());
params.put(SessionParameter.OBJECT_FACTORY_CLASS,
"org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl");
List<Repository> repos = sessionFactory.getRepositories(params);
if (repos.isEmpty()) {
throw new RuntimeException("Server has no repositories!");
}
Session session = repos.get(0).createSession();
//get site document library container
CmisObject folder = (AlfrescoFolder) session.getObjectByPath("/sites/{siteshotname}/documentLibrary");
//upload document
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document");
properties.put(PropertyIds.SECONDARY_OBJECT_TYPE_IDS, "cm:titled");
// single-value property
properties.put("xx:Xxx", xxx);
properties.put(PropertyIds.NAME, "xxx");
//multi-value property
List<String> xxList = new ArrayList<String>();
xxList.add("xx");
xxList.add("xx");
xxList.add("xx");
properties.put("my:xx", xx); // multi-value property
//perform upload
File file = new File("d:\\xx.pdf");
InputStream fis = new FileInputStream(file);
DataInputStream dis = new DataInputStream(fis);
byte[] bytes = new byte[(int) file.length()];
dis.readFully(bytes);
ContentStream contentStream = new ContentStreamImpl(file
.getAbsolutePath(), BigInteger.valueOf(bytes.length), "application/pdf",
new ByteArrayInputStream(bytes));
AlfrescoDocument newDocument = (AlfrescoDocument) folder
.createDocument(properties, contentStream, vs);
05-14-2015 01:25 AM
import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.alfresco.cmis.client.AlfrescoDocument;
import org.alfresco.cmis.client.AlfrescoFolder;
import org.apache.chemistry.opencmis.client.api.CmisObject;
import org.apache.chemistry.opencmis.client.api.Repository;
import org.apache.chemistry.opencmis.client.api.Session;
import org.apache.chemistry.opencmis.client.api.SessionFactory;
import org.apache.chemistry.opencmis.client.runtime.SessionFactoryImpl;
import org.apache.chemistry.opencmis.commons.PropertyIds;
import org.apache.chemistry.opencmis.commons.SessionParameter;
import org.apache.chemistry.opencmis.commons.data.ContentStream;
import org.apache.chemistry.opencmis.commons.enums.BindingType;
import org.apache.chemistry.opencmis.commons.enums.VersioningState;
import org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl;
public class FileUploadCMIS {
public void uploadDocument(File fileobj,
String filename, String filetype, String description,
String destination, String ipaddress, String pass, String siteid) throws IOException{
String url = "http://'+ipaddress+':8080/alfresco/cmisatom";
try {
SessionFactory sessionFactory = SessionFactoryImpl.newInstance();
Map<String, String> params = new HashMap<String, String>();
params.put(SessionParameter.USER, "admin");
params.put(SessionParameter.PASSWORD, pass);
params.put(SessionParameter.ATOMPUB_URL, url);
params.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());
params.put(SessionParameter.OBJECT_FACTORY_CLASS,
"org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl");
List<Repository> repos = sessionFactory.getRepositories(params);
if (repos.isEmpty()) {
throw new RuntimeException("Server has no repositories!");
}
Session session = repos.get(0).createSession();
//get site document library container
CmisObject folder = (AlfrescoFolder) session.getObjectByPath("/sites/"+siteid+"/documentLibrary");
//upload document
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(PropertyIds.OBJECT_TYPE_ID, "D:rs:receiptsDoc");
//properties.put(PropertyIds.SECONDARY_OBJECT_TYPE_IDS, "rs:receiptsDoc");
// single-value property
properties.put("rs:vendor", "some vendor");
properties.put(PropertyIds.NAME, "some name");
//multi-value property
List<String> xxList = new ArrayList<String>();
xxList.add("item 1");
xxList.add("item 2");
xxList.add("item 3");
properties.put("rs:itemName", xxList); // multi-value property
//perform upload
File file = new File(fileobj.getAbsolutePath());
InputStream fis = new FileInputStream(file);
DataInputStream dis = new DataInputStream(fis);
byte[] bytes = new byte[(int) file.length()];
dis.readFully(bytes);
ContentStream contentStream = new ContentStreamImpl(file
.getAbsolutePath(), BigInteger.valueOf(bytes.length), "application/pdf",
new ByteArrayInputStream(bytes));
VersioningState vs = null;
AlfrescoDocument newDocument = (AlfrescoDocument)((AlfrescoFolder)folder).createDocument(properties, contentStream, vs);
} catch (Exception e) {
e.printStackTrace();
}
}
}
12-10-2015 08:52 AM
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.