Question

Where and how should I define allowedMimeTypes and other properties for UploadFormat with Restler


This is related to Handling file uploads with Restler and item 2 in the answer section


Was it helpful?

Solution

UploadFormat is special as it throws exceptions at the get stage before we do routing to find the correct api method to call, so settings can only be done in index.php level

If the allowedMimeTypes are same across all api classes this is straight forward otherwise you need to do something like

if (false !== strpos($_SERVER['REQUEST_URI'], 'document')) {
    UploadFormat::$allowedMimeTypes = array('application/pdf'); //,'image/jpeg'
}

In the example makes PDF as the only option when the called url contains the string "document"

We have also added a new feature today which enables handling the exception thrown at the api method level

UploadFormat::$suppressExceptionsAsError = true;

will pass the exception along with the file info

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top