cancel
Showing results for 
Search instead for 
Did you mean: 

Upload error

davtrasher
Champ in-the-making
Champ in-the-making
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
12 REPLIES 12

krithika123
Champ in-the-making
Champ in-the-making
The above requirement is a bit urgent.An add on to this is the same works in java api but not in js.It would be very kind if someone could  revert back asap.

Thanks a lot.

Krithika

dark_rider
Champ on-the-rise
Champ on-the-rise
We have the same error ( From (ServerResponse): java.io.IOException: Server returned HTTP response code: 400 )
Any solution?

kevinr
Star Contributor
Star Contributor
Hi,

We haven't seen this error - on any files binary or otherwise. Do you always get it, is it a specific file?