Welcome Guest, Not a member yet? Register   Sign In
rest library
#1

[eluser]billmce[/eluser]
I've had some success in getting the Phil Sturgeon rest library working. I'm using the client side to interact with the Alfresco Document Management System.

I'm able to authenticate and obtain a ticket.
When I use a view such as:
Code:
<form action="<?php echo $action;?>" method="post" enctype="multipart/form-data" accept-charset="utf-8">
which translates out to
Code:
<form action="http://192.168.117.60:8080/alfresco/service/tests/uploadform?alf_ticket=TICKET_8cad96e208752c03142cb3981c53e4325642d51b" method="post" enctype="multipart/form-data" accept-charset="utf-8">

Then all works well. I know I'm passing the uri the authentication ticket required on the server.

What I'd like to do however is to have my view/form return to the original controller/method where I can apply some logic, tests etc. and then post the form. What I'd trying to do in my controller is use:
Code:
$this->rest->post("alfresco/service/tests/uploadform?alf_ticket=" . $ticket, array('name'=>'','file'=>$_POST['file']));

This just hangs ... so I've got something wrong. I don't think I'm passing all the variables required by the server side.

The script on the server side may yield a clue to those with more javascript than me (near zero).
Code:
for each (field in formdata.fields) {
    [removed](field.value);
    if (field.name == "name") {
        model.name = field.value;
    }
    if (field.name == "file" && field.isFile) {
        filename = field.filename;
        content = field.content;
        mimetype = field.mimetype;
    }
}
var results = search.luceneSearch("+PATH:\"app:company_home/*\" +TYPE:\"cm:folder\" +@cm\\:name:\"TEST\"");
var targetFolder = results[0];
var newDoc = targetFolder.createFile(filename);
newDoc.properties.content.write(content);
newDoc.properties.content.mimetype = mimetype;
newDoc.save();

What variables does the javascript on the server side require?
Am I using the right syntax in the rest library to pass these variables?

Thanks in advance.
#2

[eluser]billmce[/eluser]
I think a) this should be a multipart form and b) I've got to pass all the multipart info to the post command somehow (see http://ellislab.com/codeigniter/user-gui...ading.html for $this->upload->data() info).

So what do I need to accomplish this? Some code might help you. :-)
My controller:
Code:
<?php
class Alfresco extends Controller {

    function __construct()
    {
    parent::Controller();
    //get the name of the alfresco server.
    $alf_server = $this->config->item('alf_server');
        $this->load->library('rest', array(
        'server' => $alf_server
        ));
    }

    function upload(){
        
     $alf_connect=$this->rest->get('alfresco/service/api/login?u=user&pw=password');
     $ticket=trim($alf_connect[0]);
    
     // Alfresco sends back this value "<" and a 403. Picking up the 403 would be better.
     if($ticket == "<")
     {
         echo "Server down? Wierd value!!<br />";
         //we have to do something here
     }
     else
     {
         echo "Things are good ... got ticket " . $ticket;
     }
    
     $data['ticket']=$ticket;  
     $data['action']= $this->config->item('alf_server') .
                      "alfresco/service/" .
                      $this->config->item('alf_web_script_dir') .
                      "/uploadform?alf_ticket=" . $ticket;
            
    //If we've submitted the form then we upload, otherwise the view.
    if(empty($_POST['btn_upload']))
    {
        $this->load->helper('form');
        $data['robots'] = '&lt;meta name="robots" content="noindex,nofollow"&gt;';
        $data['title']="Upload";  //shows up on tab
        $data['pagetitle']="Upload Screen";  //top of page body
        $this->load->view('header_view',$data);
        $this->load->view('menu_view');
        $this->load->view('upload_view', $data);  
        $this->load->view('footer_view',$data);
    }
    else
    {
        //    submitted here.
        echo "Value of file is " . $_POST['name'];
        echo "Value of file is " . $_POST['file'];  // * * * Has no value * * *
    
        $this->rest->post('alfresco/service/tests/uploadform?alf_ticket=' . $ticket, array('name' => '','file' => $_POST['file']),'application/html');
        
    }
    }
}

?&gt;

And this is the view.
Code:
&lt;?php
?&gt;
<fieldset>
<legend>Upload File</legend>

&lt;?php echo form_open_multipart('alfresco/upload');?&gt;
<ol>
<li><label for="Name">Name:</label>&lt;input name="name"&gt;&lt;/li>
<li><label for="File">File:</label>&lt;input type="file" name="file"&gt;&lt;/li>
</ol>
</fieldset>
<fieldset class="submit">
&lt;?php //&lt;input type="submit" name="btn_upload" value="Upload"&gt; ?&gt;
&lt;?php echo form_submit('btn_upload','Upload'); ?&gt;
</fieldset>
&lt;/form&gt;

Any guidance on how to use the rest library like this ? ... or am I completely off base?
Thanks in advance.




Theme © iAndrew 2016 - Forum software by © MyBB