Hi,
I have been asked to use a restful API (I believe that's what it's called to retrieve and post files to a folder on the web - or in the cloud as is the common term now).
How do I do this from VFP?
I have been given the following information:
Viewing:
To view a document simply go to the following URL. It will output a pdf file.
http://***.***.***.***/api/index.php/documents/index/Example of a live document:
http://***.***.***.***/api/index.php/documents/index/8CF8797D-4FDF-7A4C-3750-4C8BFF1A4BC4Uploading:
To upload a file you have to do a HTTP POST to this URL:
http://***.***.***.***/api/index.php/claims/uploadIt expects 2 parameters:
doc_pk - the primary key for the field in the ClaimDocuments table which holds the description etc on the document
pdf - this should be a base64 encoded string of the contents of the file to upload
This is a sample of the code I use to upload a document:
$response = $this->rest->post('claims/upload', array(
'doc_pk'=> $doc_pk,
'pdf' => base64_encode(file_get_contents('resources/img/doctors.jpg'))
), 'json');
As you can see I first read the contents of the file, then encode it, then send it to the RESTful server.
The server will return a response in JSON. This is the php dump of that response:
stdClass Object
(
[error] => false
[message] => File uploaded successfully.
)
The error variable will be true or false. The message will correspond to the error state.
To force an error you can POST to the URL with no variables.