1 Star 11 Fork 7

无语西风 / yii2-api

 / 详情

请问如果接口是上传文件的,参数应该如何写呢?

Backlog
Opened this issue  
2019-04-22 15:58
No description.

Comments (3)

xuzhibin created任务

1,文件流方式
params()
'image'=>['type'=>'file','validate'=>'','demo'=>'','description'=>'在文件域中使用image'],

handle直接获取,单个文件
\yii\web\UploadedFile::getInstanceByName('image');
或者,多个文件
\yii\web\UploadedFile::getInstancesByName('image');

2,base64方式
params()
'image'=>['type'=>'file','validate'=>'string,required','demo'=>'data:image/png;base64,xxxxxxxxxxxxx','description'=>'base64方式'],

handle直接获取

if( preg_match('/^(data:\s*image\/(\w+);base64,)/', $params['image'], $result) )
{
    $image = base64_decode(str_replace($result[1], '', $params['image']));
}
file_put_contents($path, $image);

后面会加入基于 \yii\validators\FileValidator 的file验证

Sign in to comment

Status
Assignees
Milestones
Pull Requests
Successfully merging a pull request will close this issue.
Branches
Planed to start   -   Planed to end
-
Top level
Priority
参与者(2)
129672 wuyuxifeng 1578918874
PHP
1
https://gitee.com/wuyuxifeng/yii2-api.git
git@gitee.com:wuyuxifeng/yii2-api.git
wuyuxifeng
yii2-api
yii2-api

Search