上传取消任务


接口说明

支持版本>=10.0.5

上传文件,支持取消上传

HWH5.uploadFileOperation

请求参数

参数 类型 必填 说明
serverUrl String 服务器地址,绝对路径
formData Object 自定义body中的其他数据,json结构。注意:无数据时,需传空值 {}
filePath String 文件存放到本地的地址,包含文件名称及后缀
zip Bool true:压缩后传,false:不压缩上传
name String 开发者在服务器端通过该key可以获取到文件二进制内容
headers Object 自定义的header信息
timeout Number 超时,单位毫秒。例如:6000毫秒=6秒
progress Number 是否返回上传进度。1:返回,0:不返回。默认为 0
onProgress Function 当progress为1时,必填。回调函数,持续回调
onSuccess Function 上传成功后回调函数
onError Function 上传失败或是异常的回调函数

返回说明

参数 类型 说明
abort Function 取消上传函数
  • ES6示例

    const filePath = '/downloads/xxxx.asr';
    const _appId = 'com.huawei.xxx';
    const _appName = 'xxxxxx';
    const _userId = 'xxx';
    
    const uploadTask = await HWH5.uploadFileOperation({
      serverUrl: '/mcloud/mag/ProxyForUpload/xxx/xxx/xxxxxx', // 示例地址,非真实服务
      filePath,
      name: 'voiceFile',
      headers: {
        'X-HIC-info': `{"appId":${_appId},"appName":${_appName},"userId":${_userId}}`
      },
      formData: {},
      timeout: 60000,
      progress: 1,
      onProgress: _data => console.log('进度', _data),
      onSuccess: res = > console.log('--------- success', res),
      onError: err => console.log('--------- error', err)
    });
    
    uploadTask.abort(); //取消上传
    
  • ES5示例

    var filePath = '/downloads/xxxx.asr';
    var _appId = 'com.huawei.xxx';
    var _appName = 'xxxxxx';
    var _userId = 'xxx';
    
    HWH5.uploadFile({
      serverUrl: '/mcloud/mag/ProxyForUpload/xxx/xxx/xxxxxx', // 示例地址,非真实服务
      filePath,
      name: 'voiceFile',
      headers: {
        'X-HIC-info': 'appId:' + _appId + ',appName:' + _appName + ',userId:' + _userId
      },
      formData: {},
      timeout: 60000,
      progress: 1,
      onProgress: function (_data) {
        console.log('进度', _data);
      },
      onSuccess: function (res) {
        console.log('--------- success', res);
      },
      onError: function (err) {
        console.log('--------- error', err);
      }
    }).then(function (uploadTask) {
       uploadTask.abort(); // 取消上传
    })
    
  • 服务端接受(Spring boot)示例:

    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/xxx/xxxxxx", method = RequestMethod.POST)
    public @ResponseBody Map shortOutlineAsr(
                                           @RequestParam(name = "voiceFile") MultipartFile voiceFile,
                                           @RequestParam(name = "capKey") String capKey,
                                           @RequestParam(name = "audioFormat") String audioFormat,
                                           @RequestHeader(name = HisHeader.X_HIC_INFO) String hisInfo)
                                           {
                                            // 方法体
                                           }
    

result. ""

    Not Found. ""