/** * Gets a single file for rendering * * @param ServiceBase $api The service base * @param array $args Arguments array built by the service base * @return string * @throws SugarApiExceptionMissingParameter|SugarApiExceptionNotFound */ public function getFile($api, $args) { // Get the field if (empty($args['field'])) { // @TODO Localize this exception message throw new SugarApiExceptionMissingParameter('Field name is missing'); } $field = $args['field']; // Get the bean $bean = $this->loadBean($api, $args); if (!$bean->ACLAccess('view')) { throw new SugarApiExceptionNotAuthorized('No access to view records for module: ' . $args['module']); } if (empty($bean->{$field})) { // @TODO Localize this exception message throw new SugarApiExceptionNotFound("The requested file {$args['module']} :: {$field} could not be found."); } // Handle ACL $this->verifyFieldAccess($bean, $field); $def = $bean->field_defs[$field]; //for the image type field, forceDownload set default as false in order to display on the image element. $forceDownload = $def['type'] == 'image' ? false : true; if (isset($args['force_download'])) { $forceDownload = (bool) $args['force_download']; } require_once 'include/download_file.php'; $download = new DownloadFileApi($api); try { $download->getFile($bean, $field, $forceDownload); } catch (Exception $e) { throw new SugarApiExceptionNotFound($e->getMessage(), null, null, 0, $e); } }