首页
下载
文档
社区
视频
捐赠
源代码
赞助商
AOT 编译器
AI 助理
商业产品
PHP AOT 原生编译器
Swoole-Compiler 代码加密器
CRMEB 新零售社交电商系统
登录
注册
全部
提问
分享
讨论
建议
公告
开发框架
CodeGalaxy
发表新帖
关于 addfile 上传multipart/form-data 表单形式的文件问题
希望得到给位大神的指导。 环境: PHP8.1 +swoole 6.02 调用openai 的画图模型gpt-image-1进行图片编辑,根据官方文档: ``` curl -s -D >(grep -i x-request-id >&2) -o >(jq -r '.data[0].b64_json' | base64 --decode > gift-basket.png) -X POST "https://api.openai.com/v1/images/edits" -H "Authorization: Bearer $OPENAI_API_KEY" -F "model=gpt-image-1" -F "image[]=@body-lotion.png" -F "image[]=@bath-bomb.png" -F "image[]=@incense-kit.png" -F "image[]=@soap.png" -F 'prompt=Generate a photorealistic image of a gift basket on a white background labeled "Relax & Unwind" with a ribbon and handwriting-like font, containing all the items in the reference pictures' ``` 我使用swoole客户端请求, (1)构造 addfile需要的上传文件: ```php foreach ($this->pd['file'] as $key=>$file ) { $path = parse_url($file, PHP_URL_PATH); if ( $minitype = MiniType::get( strtolower(pathinfo($path, PATHINFO_EXTENSION)), 'image')) { $tmp = tempnam(sys_get_temp_dir(), 'img_'); file_put_contents($tmp, file_get_contents($file)); $this->Clientfile[] = [$tmp, 'image', $minitype , basename($path)]; } } ``` (2)客户端的addfile 循环增加文件列表: ```php foreach ( $this->Clientfile as $file) { $client->addFile(...$file); } ``` 问题点: (1)当只有一张图片时,使用 'image' 作为form表单字段名正常 ; 使用'image[]' 服务端显示缺失 image字段; (2)当有多张图片时,使用 'image' 作为form表单字段名提示image参数重复错误; 使用'image[]' 服务端显示依然缺失 image字段; ```php "error": { "message": "Duplicate parameter: 'image'. You provided multiple values for this parameter, whereas only one is allowed. If you are trying to provide a list of values, use the array syntax instead e.g. 'image[]=<value>'.", "type": "invalid_request_error", "param": "image", "code": "duplicate_parameter" } ``` 针对swoole的 addfile 应该如何上传 同一个数组字段名的文件呢?
发布于1年前 · 0 次浏览 · 来自
提问
廖龙
希望得到给位大神的指导。 环境: PHP8.1 +swoole 6.02 调用openai 的画图模型gpt-image-1进行图片编辑,根据官方文档: ``` curl -s -D >(grep -i x-request-id >&2) -o >(jq -r '.data[0].b64_json' | base64 --decode > gift-basket.png) -X POST "https://api.openai.com/v1/images/edits" -H "Authorization: Bearer $OPENAI_API_KEY" -F "model=gpt-image-1" -F "image[]=@body-lotion.png" -F "image[]=@bath-bomb.png" -F "image[]=@incense-kit.png" -F "image[]=@soap.png" -F 'prompt=Generate a photorealistic image of a gift basket on a white background labeled "Relax & Unwind" with a ribbon and handwriting-like font, containing all the items in the reference pictures' ``` 我使用swoole客户端请求, (1)构造 addfile需要的上传文件: ```php foreach ($this->pd['file'] as $key=>$file ) { $path = parse_url($file, PHP_URL_PATH); if ( $minitype = MiniType::get( strtolower(pathinfo($path, PATHINFO_EXTENSION)), 'image')) { $tmp = tempnam(sys_get_temp_dir(), 'img_'); file_put_contents($tmp, file_get_contents($file)); $this->Clientfile[] = [$tmp, 'image', $minitype , basename($path)]; } } ``` (2)客户端的addfile 循环增加文件列表: ```php foreach ( $this->Clientfile as $file) { $client->addFile(...$file); } ``` 问题点: (1)当只有一张图片时,使用 'image' 作为form表单字段名正常 ; 使用'image[]' 服务端显示缺失 image字段; (2)当有多张图片时,使用 'image' 作为form表单字段名提示image参数重复错误; 使用'image[]' 服务端显示依然缺失 image字段; ```php "error": { "message": "Duplicate parameter: 'image'. You provided multiple values for this parameter, whereas only one is allowed. If you are trying to provide a list of values, use the array syntax instead e.g. 'image[]=<value>'.", "type": "invalid_request_error", "param": "image", "code": "duplicate_parameter" } ``` 针对swoole的 addfile 应该如何上传 同一个数组字段名的文件呢?
赞
0
收藏
提问
分享
讨论
建议
公告
开发框架
CodeGalaxy
登录
后参与评论
评论
还没有评论!