简体   繁体   English

如何在Restler中为UploadFormat定义静态属性?

[英]How to define static properties for UploadFormat in Restler?

Where and how should I define allowedMimeTypes and other properties for UploadFormat with Restler 我应该在哪里以及如何使用Restler为UploadFormat定义allowedMimeTypes和其他属性


This is related to Handling file uploads with Restler and item 2 in the answer section 这与使用Restler和答案部分中的项目2 处理文件上传有关


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 UploadFormat是特殊的,因为它在进行路由以找到正确的api方法进行调用之前会在get阶段引发异常,因此只能在index.php级别进行设置

If the allowedMimeTypes are same across all api classes this is straight forward otherwise you need to do something like 如果所有API类中的allowedMimeTypes都相同,这很简单,否则您需要执行类似的操作

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" 在示例中,当被调用的url包含字符串“ document”时,使PDF作为唯一选项

We have also added a new feature today which enables handling the exception thrown at the api method level 我们今天还添加了一个新功能,该功能可以处理api方法级别引发的异常

UploadFormat::$suppressExceptionsAsError = true;

will pass the exception along with the file info 将与文件信息一起传递异常

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM