Accessing files from File Upload field type via REST API or

Posted by Rollbase User on 26-Dec-2011 20:35

I am creating an PHP script that will merge multiple pdf documents uploaded to a couple rollbase records into one PDF document. File Upload Users can upload a file which can be accessible through this field, and optionally indexed as part of the search engine. You can specify a maximum size for files from 128KB up to 2MB. However, I can not access the uploaded files via the URL: http://www.rollbase.com/prod1/servlet/File?dir=data&objDefId=' . $OBJDEF_ID . '&id=' . $recordId . '&name=' . $NAME . '&sessionId=' . $sessionID When I view the URL in a web browser (after logging into rollbase), the uploaded file can be accessed, however the session id is not allowing access from our php web server. I also tried logging in via REST API and using that session ID, but it does not work.The getDataField REST API also does appear to be working for uploaded files. Do you have any suggestions on how I would be able to get access to uploaded files attached to Rollba

All Replies

Posted by Admin on 27-Dec-2011 11:35
You can use REST API getBinaryData - please check Chapter 15 for more info.
Posted by Admin on 25-Jan-2012 22:36
I am trying to use the new REST API for setBinaryData using a PHP script, however, the uploaded file never opens when I view the record in Rollbase. A file gets uploaded, but it doesn't contain anything.





function UploadFile($url,$pdfString)

{

$session = curl_init($url);

curl_setopt($session, CURLOPT_POST, true);

curl_setopt($session, CURLOPT_POSTFIELDS, $pdfString);

curl_setopt($session, CURLOPT_HEADER, false);

curl_setopt($session, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($session);

curl_close($session);

print_r($response);

}



//assume $pdfString is a valid pdf converted into a string

$url = 'http://www.rollbase.com/rest/api/setBinaryData?sessionId='.$sessionID.'&id='.$rbid.'&fieldName=upload&fileName=MyFile.pdf&contentType=application/pdf';

UploadFile($url, $pdfString);





In the documentation it says:



"Request Body - Binary content of uploaded file"



Does this mean a string containing the binary content of the file?



Thank you
Posted by Admin on 26-Jan-2012 12:43
I will change this API to accept base-64 encoded values
This thread is closed