Erreur d'upload
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-05-2008 03:31 AM
Bonjour,
Je tente d'uploader des fichiers vers alfresco 2.9c avec les apis rest. L'upload réussi mais les fichiers sont illisibles.
méthode post:
webscript upload:
élément : workspace://SpacesStore/636eb6a8-623d-11dd-948f-7b708f4f69e0
lecteur : null
Veuillez contacter votre administrateur système."
Quand j'utilise upload.properties.content.setcontent(content) le document fait la bonne taille, a le bon nombre de page, mais je n'obtient que des pages blanches.
D'après vous l'erreur viendrait plutot du script ou du code? Merci
Je tente d'uploader des fichiers vers alfresco 2.9c avec les apis rest. L'upload réussi mais les fichiers sont illisibles.
méthode post:
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); }
webscript upload:
var filename = null;var content = null;var title = "";var description = "";var nodeid = "";var TypeExam = "";var mimetype = "";// locate file attributesfilename = 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 locatedif (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 nodeidif ((nodeid) && (nodeid != "")){ model.folder = search.findNode("workspace://SpacesStore/" +nodeid);} upload = model.folder.createFile(filename) ; upload.specializeType("{my.new.model}compte_rendu"); upload.properties.content.write(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;}
Quand j'utilise upload.properties.content.write(content), j'ouvre le document il contient ceci "Le contenu de l'élément est manquant : élément : workspace://SpacesStore/636eb6a8-623d-11dd-948f-7b708f4f69e0
lecteur : null
Veuillez contacter votre administrateur système."
Quand j'utilise upload.properties.content.setcontent(content) le document fait la bonne taille, a le bon nombre de page, mais je n'obtient que des pages blanches.
D'après vous l'erreur viendrait plutot du script ou du code? Merci
Labels:
- Labels:
-
Archive
6 REPLIES 6

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2008 10:04 AM
Essaye avec l'instruction suivante :
J'espère que c'est pareil avec la 2.9C.
Christophe
upload.properties.content.content = content;
Avec la version 2.1.1 d'Alfresco ça fonctionne mais j'avais des problème avec l'instruction :upload.properties.content.encoding = "UTF-8";
je l'ai donc enlevée et ça passe.J'espère que c'est pareil avec la 2.9C.
Christophe
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2008 03:44 AM
J'ai essayé avec upload.properties.content.content = content;
et sans upload.properties.content.encoding = "UTF-8";
mais j'ai toujours des pages blanches :?
Merci quand même.
et sans upload.properties.content.encoding = "UTF-8";
mais j'ai toujours des pages blanches :?
Merci quand même.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2008 10:57 AM
Bonjour,
avez-vous essayé ceci :
avez-vous essayé ceci :
upload.properties.content.write(content);upload.properties.content.mimetype = "UTF-8";upload.properties.title = "mon fichier uploadé";upload.save();
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2008 03:53 AM
Oui j'ai essayé
résultat: la méthode org.alfresco.repo.jscript.ScriptNode$ScriptContentData.write(string) est introuvable.
résultat: la méthode org.alfresco.repo.jscript.ScriptNode$ScriptContentData.write(string) est introuvable.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2008 12:00 PM
Le problème vient peut être de la méthode POST où je passe un String pour le paramètre content. A noté que si j'upload un simple .TXT je peux le lire dans alfresco.
D'autres propositions ?
D'autres propositions ?
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2008 10:56 AM
J'ai essayé une autre métode pour effectuer mon upload:
Cette fois-ci dans la réponse fournie par le serveur j'ai le "loginform" alfresco, il y a donc un problème d'authentification pourtant je lui passe bien le ticket dans l'outputstream…
public String uploadDocs(String title, String description, String correspondant,String nodeid){ HttpURLConnection conn = null; BufferedReader br = null; DataOutputStream dos = null; DataInputStream inStream = null; InputStream is = null; OutputStream os = null; boolean ret = false; String StrMessage = ""; String exsistingFileName = "D:\\Docs_scannes\\PDF\\advanced-workflow-article.pdf"; String lineEnd = "\r\n"; String twoHyphens = "–"; String boundary = "*****"; int bytesRead, bytesAvailable, bufferSize; byte[] buffer; int maxBufferSize = 1*1024*1024; String responseFromServer = ""; String urlString = "http://localhost:8082/alfresco/wcservice/sample/uploadNew"; try { //—————— CLIENT REQUEST FileInputStream fileInputStream = new FileInputStream( new File(exsistingFileName) ); // open a URL connection to the Servlet URL url = new URL(urlString); // Open a HTTP connection to the URL conn = (HttpURLConnection) url.openConnection(); // Allow Inputs conn.setDoInput(true); // Allow Outputs conn.setDoOutput(true); // Don't use a cached copy. conn.setUseCaches(false); // Use a post method. conn.setRequestMethod("POST"); conn.setRequestProperty("Connection", "Keep-Alive"); conn.setRequestProperty("Content-Type", "multipart/form-data;boundary="+boundary); dos = new DataOutputStream( conn.getOutputStream() ); dos.writeBytes(twoHyphens + boundary + lineEnd); dos.writeBytes("Content-Disposition: form-data; name=\"nodeid\"" + lineEnd + lineEnd); System.out.println(nodeid + lineEnd); dos.writeBytes( nodeid + lineEnd); dos.writeBytes(twoHyphens + boundary + lineEnd); dos.writeBytes("Content-Disposition: form-data; name=\"file\";" + " filename=\"" + exsistingFileName +"\"" + lineEnd); dos.writeBytes(lineEnd); dos.writeBytes(twoHyphens + boundary + lineEnd); dos.writeBytes("Content-Disposition: form-data; name=\"title\"" + lineEnd + lineEnd); dos.writeBytes( title + lineEnd); System.out.println(title + lineEnd); dos.writeBytes(twoHyphens + boundary + lineEnd); dos.writeBytes("Content-Disposition: form-data; name=\"desc\"" + lineEnd + lineEnd); dos.writeBytes( description + lineEnd); dos.writeBytes(twoHyphens + boundary + lineEnd); dos.writeBytes("Content-Disposition: form-data; name=\"author\"" + lineEnd + lineEnd); dos.writeBytes( correspondant + lineEnd); dos.writeBytes(twoHyphens + boundary + lineEnd); dos.writeBytes("Content-Disposition: form-data; name=\"ticket\"" + lineEnd + lineEnd); dos.writeBytes( getTicket() + lineEnd); // create a buffer of maximum size bytesAvailable = fileInputStream.available(); bufferSize = Math.min(bytesAvailable, maxBufferSize); buffer = new byte[bufferSize]; // read file and write it into form… bytesRead = fileInputStream.read(buffer, 0, bufferSize); while (bytesRead > 0) { dos.write(buffer, 0, bufferSize); bytesAvailable = fileInputStream.available(); bufferSize = Math.min(bytesAvailable, maxBufferSize); bytesRead = fileInputStream.read(buffer, 0, bufferSize); } // send multipart form data necesssary after file data… dos.writeBytes(lineEnd); dos.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd); // close streams fileInputStream.close(); dos.flush(); dos.close(); } catch (MalformedURLException ex) { System.out.println("From ServletCom CLIENT REQUEST:"+ex); } catch (IOException ioe) { System.out.println("From ServletCom CLIENT REQUEST:"+ioe); } //—————— read the SERVER RESPONSE try { inStream = new DataInputStream ( conn.getInputStream() ); String str; while (( str = inStream.readUTF()) != null) { System.out.println("Server response is: "+str); System.out.println(""); } inStream.close(); } catch (IOException ioex) { System.out.println("From (ServerResponse): "+ioex); } return urlString; }
Et le script correspondant:// get folder to upload into with nodeidif ((args.nodeid) && (args.nodeid != "")){ model.folder = search.findNode("workspace://SpacesStore/" + args.nodeid);}var filename = null;var content = null;var mimetype = null;encoding = null;var title = null;var description = null;var author = null;var name = null;// locate file attributesfor each (field in formdata.fields){ if (field.name == "title") { title = field.value; } else if (field.name == "desc") { description = field.value; } else if (field.name == "author") { author = field.value; } else if (field.name == "name") { // for having name properties different than original filename name = field.value; } else if (field.name == "file" && field.isFile) { filename = field.filename; content = field.content; encoding = "UTF-8"; }}if ((args.mimetype) && (args.mimetype != "")){ mimetype = args.mimetype;}// ensure folder and mandatory file attributes have been locatedif (model.folder == null || filename == undefined || content == undefined){ status.code = 400; status.message = "Uploaded file cannot be located in request"; status.redirect = true;}else{ // create document in model.folder for uploaded file upload = model.folder.createFile("upload" + model.folder.children.length + "_" + filename); upload.properties.content.write(content); upload.properties.content.encoding = encoding; upload.properties.content.mimetype = mimetype; if (name != null) { upload.properties.name = name; } else { upload.properties.name = filename; } if (title != null) { upload.properties.title = title; } if (description != null) { upload.properties.description = description; } if (author != null) { upload.properties.author = author; } upload.save(); // setup model for response template model.upload = upload;}
Cette fois-ci dans la réponse fournie par le serveur j'ai le "loginform" alfresco, il y a donc un problème d'authentification pourtant je lui passe bien le ticket dans l'outputstream…
