<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);
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 Ko
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();
}
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
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.