AnsweredAssumed Answered

Upload error

Question asked by davtrasher on Aug 6, 2008
Latest reply on Nov 24, 2010 by kevinr
Hi,
I try to upload files to alfresco2.9c with rest api. The upload succeed but files are empty
post method:

String adresse= "/alfresco/wcservice/sample/upload?";
      try {
         //encodage des paramètres de la requête
         String donnees = URLEncoder.encode("filename", "UTF-8")+
         "="+URLEncoder.encode(nomDoc, "UTF-8");
         donnees += "&"+URLEncoder.encode("content", "UTF-8")+
         "=" + URLEncoder.encode(content, "UTF-8");
         donnees += "&"+URLEncoder.encode("mimetype", "UTF-8")+
         "=" + URLEncoder.encode(mimetype, "UTF-8");
         donnees += "&"+URLEncoder.encode("title", "UTF-8")+
         "=" + URLEncoder.encode(title, "UTF-8");
         donnees += "&"+URLEncoder.encode("description", "UTF-8")+
         "=" + URLEncoder.encode(description, "UTF-8");
         donnees += "&"+URLEncoder.encode("TypeExam", "UTF-8")+
         "=" + URLEncoder.encode(TypeExam, "UTF-8");
         donnees += "&"+URLEncoder.encode("nodeid", "UTF-8")+
         "=" + URLEncoder.encode(nodeid, "UTF-8");
         donnees += "&"+URLEncoder.encode("ticket", "UTF-8")+
         "=" + URLEncoder.encode(getTicket(), "UTF-8");

         //création de la connection
         URL url = new URL(getUrlContext()+adresse);
         URLConnection conn = url.openConnection();
         conn.setDoOutput(true);

         //envoi de la requête
         writer = new OutputStreamWriter(conn.getOutputStream());
         writer.write(donnees);
         writer.flush();

         //lecture de la réponse
         reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
         while ((ligne = reader.readLine()) != null) {
            System.out.println(ligne);
         }
upload webscript :

Code: Tout sélectionner
var filename = null;
var content = null;
var title = "";
var description = "";
var nodeid = "";
var TypeExam = "";
var mimetype = "";

// locate file attributes
filename = args['filename'];
content = args['content'];
mimetype = args['mimetype'];
title = args['title'];
description = args['description'];
nodeid = args ['nodeid'];
TypeExam = args['TypeExam'];

// ensure mandatory file attributes have been located
if (filename == undefined || content == undefined)
{
  status.code = 400;
  status.message = "Uploaded file cannot be located in request";
  status.redirect = true;
}
else
{
// get folder to upload into with nodeid
if ((nodeid) && (nodeid != ""))
{
   model.folder = search.findNode("workspace://SpacesStore/" +nodeid);
}
      upload = model.folder.createFile(filename) ;
            upload.specializeType("{my.new.model}compte_rendu");
            upload.properties.content.setContent(content);
            upload.properties.content.encoding = "UTF-8";
            upload.properties.content.mimetype = mimetype;
            upload.properties.title = title;
            upload.properties.description = description;
            upload.properties.TypeExam = TypeExam;
            upload.save();

  // setup model for response template
  model.upload = upload;
}
When I use upload.properties.content.write(content), the method is not found and content is "null" and when I use setContent(content), the document has the right size and pages number but is empty.

I try this too:

upload.properties.content.content = content;


Do you understand what happened?
Thanks

Outcomes