2.1 基础API-上传文件接口说明

接口说明

适用对象:开放应用

接口路由:/basic/upload-file

请求方式:POST


请求参数

参数

类型

是否必填

最大长度

描述

示例

type

string

20

上传文件类型

image

remote

string


远端文件地址

remote和file必填一项,都填时取remote字段


https://www.rrsc.cn/Public/static/index/img/v5/v5_logo.png

file

file


本地文件

remote和file必填一项,都填时取remote字段


type合法值

描述

image

图片

video

视频

audio

音频

远端文件上传请求示例

type: 'image',
remote: 'https://www.rrsc.cn/Public/static/index/img/v5/v5_logo.png'

本地文件上传请求示例

$url = "http://open.v5.getpkg.cn/addons/renren_shop/public/index.php?r=client/apps/openApi/basic/upload-file&shop-id=9";
// 初始化
$ch = curl_init($url);
// 复制临时文件
$newPath = APP_PUBLIC_TMP_PATH.'/'.$_FILES["file"]["name"];
copy($_FILES["file"]["tmp_name"], $newPath);
//  创建 CURLFile 对象
$file = new CURLFile(($newPath));
// 设置文件类型
$file->setMimeType($_FILES["file"]['type']);

$data = array(
  'file' => $file,
  'type' => 'image',
  // 其它必传参数
  // ...
);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

// 执行
$output = curl_exec($ch);

响应参数

参数

类型

是否必填

最大长度

描述

示例

path

string


文件保存路径

image/0/2021/01/d67c393759fbdf0b817dc88e0c6ec647.png


响应示例

{
    "error": 0,
    "path": "image/0/2021/01/d0c5a603f5a8d1cb445e5a66f4064978.png"
}


错误码

错误码

错误描述

解决方案

555001

上传文件错误:

不支持的附件类型

不能上传空文件

最大支持上传xxKB的文件

禁止上传此类型文件

根据提示修改参数传值


Powered by www.sdsdsoft.com-© 2001-2024 微助 备案号鄂ICP备16018351号-2      微助学院 | 微助商城| 微助互动

联系我们
8年品牌,专注移动电商
扫码立即咨询
027-63376568
QQ:1010751194