public String uploadFile(String idfolder, byte[] bytes, String fileName,
String contentType) {
String idDoc = null;
// properties
Folder folder = (Folder) session.getObject(idfolder);
Map<String, Object> newDocProps = new HashMap<String, Object>();
newDocProps.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document");
newDocProps.put(PropertyIds.NAME, fileName);
ContentStream contentStream = new ContentStreamImpl(fileName,
BigInteger.valueOf(bytes.length), contentType,
new ByteArrayInputStream(bytes));
try {
// create the file
Document doc = folder.createDocument(newDocProps, contentStream,
VersioningState.NONE);
idDoc = doc.getId();
} catch (CmisConstraintException e) {
System.out.println("No se pudo crear el archivo");
}
return idDoc;
}
Folder folder = (Folder) session.getObject(idfolder);
public void handleFileUpload(FileUploadEvent event) throws IOException {
this.file = event.getFile();
fichero = event.getFile().getContents();/* Byte */
nombreFichero = file.getFileName();
tipoFichero = file.getContentType();
directorioAlfrescoDocumento= "/carpetaDeseada/";
Controller(); /*me conecto con alfresco*/
idDocumentoEnAlfresco = uploadFile(directorioAlfrescoDocumento, fichero, nombreFichero,tipoFichero);
}
public String uploadFile(String idfolder, byte[] bytes, String fileName,
String contentType) {
String idDoc = null;
// properties
Folder folder = (Folder) session.getObject(idfolder); /*error*/
Map<String, Object> newDocProps = new HashMap<String, Object>();
newDocProps.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document");
newDocProps.put(PropertyIds.NAME, fileName);
ContentStream contentStream = new ContentStreamImpl(fileName,
BigInteger.valueOf(bytes.length), contentType,
new ByteArrayInputStream(bytes));
try {
// create the file
Document doc = folder.createDocument(newDocProps, contentStream,
VersioningState.NONE);
idDoc = doc.getId();
} catch (CmisConstraintException e) {
System.out.println("No se pudo crear el archivo");
}
return idDoc;
}
String path = "/User Homes/folder"
CmisObject object = getSession().getObjectByPath(path);
String id = object.getId();
String path = "/index/2015/";
CmisObject object = session.getObjectByPath(path);
//Sera carpeta ¿?
if (object instanceof Folder) {
// Nombre del documento
String name = file.getFileName();
String type = file.getContentType();
byte[] data2 = fichero;
Map<String, Object> properties2 = new HashMap<String, Object>();
properties2.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document");
properties2.put(PropertyIds.NAME, name);
// Se carga el contenido en un ContentStream
InputStream stream = new ByteArrayInputStream(data2);
ContentStream contentStream = new ContentStreamImpl(name,
BigInteger.valueOf(data2.length),type, stream);
// Se crea el documento
Document newDoc = ((Folder) object).createDocument(properties2,
contentStream, VersioningState.MAJOR);
urlElemento=newDoc.getContentUrl();
Content from pre 2016 and from language groups that have been closed.
Content is read-only.
By using this site, you are agreeing to allow us to collect and use cookies as outlined in Alfresco’s Cookie Statement and Terms of Use (and you have a legitimate interest in Alfresco and our products, authorizing us to contact you in such methods). If you are not ok with these terms, please do not use this website.