1.1.1. 上传文件
![]()
方法名称: fileUpload
方法说明: 上传文件,将由客户端上传文件至接入方服务器
参数说明:(“-”为子级标识)
| 参数位序号 | 参数名称 | 参数类型 | 参数说明 | 参数是否必须 | 如果是回调其回传参数 |
|---|---|---|---|---|---|
| 1 | 配置参数项 | object | 配置参数对象 | 是 | 无 |
| - | -completed | function | 获取信息的回调 上传结果的返回 requestcode: 后台服务器返回码 --return : 活动后台返回信息(子项自定义,以下为建议项) info: 返回提示 |
是 | js object{requestcode:'', return: {code:'', fileurl:'', info:''}, info:''} |
| - | -cpIncompatible | function | 环境没有实现此方法的回调 | 是 | 无 |
| - | -serviceurl | string | 远程需要上传的服务器地址 | 是 | 无 |
| - | -localfile | string | 本地文件的地址 | 是 | 无 |
| - | -filename | string | 上传后文件名称 | 是 | 无 |
| - | -inputname | string | 上传的form表单的name值 | 是 | 无 |
| - | -extend | string | 上传的附加信息form表单的name值为extend,值为json string(没有传空) | 否 | 无 |
| - | -uploadMode | string | 上传模式//‘default’,‘qiniu’,‘aliyun’,‘xsb’ | 否 | 无 |
| - | -uploadToken | string | 上传令牌//客户端和前端自定义(和上传模式对应) | 否 | 无 |
调用样例:
CP.fileUpload({
completed: function(data){
// data > {requestcode:'', return: {"code": "1", "info": "提交成功","fileurl": "http://xxx.xxx.xxx/testString.jpg"}}
CP.tools.writelog('file_upload', data);
},
cpIncompatible: function () {
CP.tools.writelog('', '此环境不支持此方法');
},
serviceurl: 'https:xxx.xxx.com?m=xxx&subm=xxx',
localfile: '',
filename: 'testString',
inputname: 'upload',
extend: "{\"keyword1\":\"111\", \"keyword2\":\"222\"}"
});
1.1.2. 客户端上传文件至接入方后台说明
提交方法
POST
提交方式
以Content-Typ 为 multipart/form-data 提交form表单
接口提交内容
提交内容样例:
--173b288b-6e3c-442b-811b-d36699e13b9e
Content-Disposition: form-data; name="upload"; filename="testString"; keyword1="111"; keyword2="222"
Content-Length: 21262
...
--173b288b-6e3c-442b-811b-d36699e13b9e--
后台接口返回建议
返回建议为json字符串格式可自定义,返回字段将在回调函数 completed 的参数data的 return 字段中。
建议样例(参照调用接口代码) {requestcode:'', return: {"code": "1", "info": "提交成功","fileurl": "http://xxx.xxx.xxx/testString.jpg"}}