cancel
Showing results for 
Search instead for 
Did you mean: 

Accessing Mime Attachments in Web Scripts

r1ch4rd
Champ in-the-making
Champ in-the-making
Hi Folks,

How can I access Mime Attachments when running at HTTP POST or PUT operation on a web script which I am writing to provide a RESTful service to my Alfresco repository?

I am writing a Share Dashlet which needs to deliver generated content (not from a file upload form) to the repository, but I can't find a way in the Web Scripts environment to access POSTed content.  Actually, further to that, I'm finding it difficult even to generate the appropriate POST using the "remote" javascript object in Share.  At the moment it looks like I'm going to have to literally mock up a mutlipart formdata POST so that I can access the content via the "formdata" Web Script object.  This is obviously a terrible way to go about this, so I must be missing something …

Any suggestions greatly appreciated.

Regards

Richard
10 REPLIES 10

venky0589
Champ in-the-making
Champ in-the-making
Hi


I want a html client to request cmis ad-hoc query webscript . query.get.cmisquery.js.

This has a specific format reader cmisquery of mimetype attached application/cmisquery+xml.
So how can I make a post request so that this format reader will invoke and read my xml.
I tried the code below it is not working

import java.io.*;
import java.net.*;




public class upload
{
public static void main(String args[]) throws IOException
{
URL                 url;
    URLConnection   urlConn;
    OutputStream    printout;
    DataInputStream     input;
    // URL of CGI-Bin script.
    url = new URL ("http://localhost:8080/alfresco/service/api/query?alf_ticket=TICKET_a0a5f3589b629e2698cfb01eac987c47d...");
    // URL connection channel.
    urlConn = url.openConnection();
    // Let the run-time system (RTS) know that we want input.
    urlConn.setDoInput (true);
    // Let the RTS know that we want to do output.
    urlConn.setDoOutput (true);
    // No caching, we want the real thing.
    urlConn.setUseCaches (false);
    // Specify the content type.
    urlConn.setRequestProperty
    ("Content-Type", "application/cmisquery+xml");
    // Send POST output.
    printout = urlConn.getOutputStream ();
File fl=new File("1.xml");
FileInputStream fis=new FileInputStream(fl);
int i=0;
byte[] bt=new byte[1024];
while((i=fis.read(bt))!=-1)
{
printout.write(bt,0,1);
}
    printout.flush ();
    printout.close ();
    // Get response data.
    input = new DataInputStream (urlConn.getInputStream ());
    String str;
    while (null != ((str = input.readLine())))
    {
    System.out.println (str);
   
    }
    input.close ();
}

}



and HTML CLIENTis


<html>
<head>
   <title>Upload Web Script Sample</title>
   <link rel="stylesheet" href="${url.context}/css/main.css" TYPE="text/css">
</head>
<body>
   <table>
     <tr>
       <td><img src="${url.context}/images/logo/AlfrescoLogo32.png" alt="Alfresco" /></td>
       <td><nobr>Upload Web Script Sample</nobr></td>
     </tr>
     <tr><td><td>Alfresco ${server.edition} v${server.version}
   </table>
   <p>
   <table>
     <form action="http://locahost:8080/alfresco/service/api/query" method="post" enctype="application/cmisquery+xml">
       <input type="file" name="query"/>
       <tr><td><td><input type="submit" name="submit" value="Upload">
     </form>
   </table>
</body>
</html>


HERE IS MY XML FILE


<?xml version="1.0"?>
<query xmlns="http://www.cmis.org/CMIS/2008/05">
<statement>SELECT name FROM DOCUMENT_OBJECT_TYPE</statement>
<searchAllVersions>false</searchAllVersions>
<pageSize>0</pageSize>
<skipCount>0</skipCount>
<returnAllowableActions>false</returnAllowableActions>
</query>



*************ANY ONE OF THE ABOVE CLIENTS ARE NOT WORKING  SO……***************

Please specify the way how can i call this webscript…









Thanks in advance

venky