Friday, June 22, 2012

Receive a file on a REST application

Hi, I'm new to cake and I'm creating an application with some resources exposed be accessed from a desktop aplication (web service)
The web service its working fine but now I need to receive a file via a POST request and I don't know how to do it. I'll appreciate the help you could give me.

this is my controller:

class TransfersController extends AppController {
public $name = 'Transfers';
public $components = array('RequestHandler');
public $helpers = array('Js');

public function record($rfc = null, $numop = null, $source = null) {        
if ($this->request->is('post')) {
if (strlen($rfc) > 0) {            
if ($numop > 0) {
$this->loadModel('Client');
$client = $this->Client->findByRfc($rfc);
if (!empty($client)) {
if ($client['Client']['enabled'] == 1) {
// code to read the file sent by POST request. help!!
// I also need help to save that file to a LONGBLOB column
// set several values to insert in the database
$this->Transfer->set('client_id', $client['Client']['id']);                        
$this->Transfer->set('operation_num', $numop);
$this->Transfer->set('source', $source);
if ($this->Transfer->save($this->request->data)) {
$message = 'Ok';
} else {
$message = 'No se pudo registrar la transmisión';
}                    
} else {
$message = 'Su cuenta ha sido suspendida.';
}
} else {
$message = 'El RFC ' . $rfc . ' no está registrado';
}
} else {
$message = 'El número de operación no es válido';
}
} else {
$message = 'El RFC no es válido';
}
} else {
$message = 'La petición es inválida';
}
$this->set('message', $message);
}
}

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
 
 
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

No comments: