06-30-2009 04:21 AM
<meta HTTP-EQUIV="Refresh" content="50;URL=http://localhost:8084/xulapps/stage/content/front/index.jsp">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%
String filename= request.getParameter("y");
String title= filename;
System.out.println("Title est de " +title);
//String ext= filename.substring(filename.lastIndexOf('.')+1, filename.length());
//title= title.replace( filename.substring(filename.lastIndexOf('.'), filename.length()), "");
// System.out.println(ext);
String contType= "";
AuthenticationUtils.startSession("admin", "admin");
Store storeRef = new Store(Constants.WORKSPACE_STORE, "SpacesStore");
String folderPath = "/app:company_home";
ParentReference companyHomeParent = new ParentReference(storeRef, null, folderPath, Constants.ASSOC_CONTAINS, null);
RepositoryServiceSoapBindingStub repositoryService =WebServiceFactory.getRepositoryService();
ContentServiceSoapBindingStub contentService =WebServiceFactory.getContentService();
NamedValue[] contentProps = new NamedValue[1];
NamedValue[] titledProps = new NamedValue[2];
// le nom du fichier
companyHomeParent.setChildName("{http://www.alfresco.org/model/content/1.0}yassine.pdf" );
/*System.out.println(filename);
String ext= testecriture.Extension(filename);
title= testecriture.replace(title);*/
CMLCreate create = new CMLCreate("1", companyHomeParent, companyHomeParent.getUuid(), Constants.ASSOC_CONTAINS, null, Constants.PROP_CONTENT, contentProps);
// Construct CML Block
contentProps[0] = Utils.createNamedValue(Constants.PROP_NAME, "yassine");
// Propriété du fichier
titledProps[0] = Utils.createNamedValue(Constants.PROP_TITLE, title);
titledProps[1] = Utils.createNamedValue(Constants.PROP_DESCRIPTION, "");
CMLAddAspect addAspect = new CMLAddAspect(Constants.ASPECT_TITLED, titledProps, null, "1");
CML cml = new CML();
cml.setCreate(new CMLCreate[] {create});
cml.setAddAspect(new CMLAddAspect[] {addAspect});
// Mettre a jour le repositroy
/*if(ext.equals("txt")){
contType= "text/plain";}
else if(ext.equals("pdf")){
contType= "application/pdf";}
else if(ext.equals("doc")|| ext.equals("docx")){
contType= "application/msword";} */
ContentFormat format = new ContentFormat("application/pdf", "UTF-8");
UpdateResult[] result = WebServiceFactory.getRepositoryService().update(cml);
Reference content = result[0].getDestination();
InputStream is = request.getInputStream();
byte[] buffer = new byte[32];
ByteArrayOutputStream os = new ByteArrayOutputStream(is.available());
int l;
do {
l = is.read(buffer);
os.write(buffer,0,l);
} while(is.available() > 0);
// le nom du fichier
contentService.write(content, Constants.PROP_CONTENT, os.toByteArray(), format);
06-30-2009 11:15 AM
06-30-2009 11:30 AM
is.close();
os.close();
mais ca ne marche toujours pas le fichier est toujours incomplet, il ne fait tout le while, j'ai un fichier .txt de 38Ko je n'uploade qu'un fichier de 7,3Ko ca si j'ai de la chance sinon c'est 3.3 Ko07-31-2009 09:36 AM
private static byte[] getOutputBytes (InputStream is)throws Exception{
ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte[] buf = new byte[2048];
int len;
while ((len = is.read(buf)) > 0)
{
bos.write(buf, 0, len);
}
return bos.toByteArray();
}
08-03-2009 03:13 AM
InputStream is = request.getInputStream();
byte[] buffer = new byte[1024];
ByteArrayOutputStream os = new ByteArrayOutputStream(is.available());
int l = 0;
while (l >= 0) {
l = is.read(buffer);
if (l != -1) {
os.write(buffer, 0, l);
}
}
is.close();
os.close();
contentService.write(content, Constants.PROP_CONTENT, os.toByteArray(), format);
merci de votre aide cordialement
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.