HWH5.uploadFile
HWH5.uploadFileOperation
HWH5.downloadFile
HWH5.downloadFileAndEncrypt
HWH5.downloadFileOperation


HWH5.uploadFile

支持版本>=10.0.2

扫码体验:

vscode-plugin

上传文件

请求参数

参数 类型 必填 说明
serverUrl String 服务器地址,绝对路径
formData Object 自定义body中的其他数据,json结构。注意:无数据时,需传空值 {}
filePath String 文件存放到本地的地址,包含文件名称及后缀(/download/test.png)
name String 开发者在服务器端通过该key可以获取到文件二进制内容
headers Object 自定义的header信息
progress Number 是否返回上传进度。1:返回,0:不返回。默认为 0
onProgress Function 当progress为1时,必填。回调函数,持续回调

注意:filePath 只能是用户选择的文件或图片,如通过chooseImage返回的图片路径

返回结果

无。

请求示例

  • ES6示例

    const filePath = '/downloads/xxxx.asr';
    const _appId = 'com.xxx.xxx';
    const _appName = 'xxxxxx';
    const _userId = 'xxx';
    
    HWH5.uploadFile({
      serverUrl: 'http://example.com/uploadFile', // 示例地址,非真实服务
      filePath,
      name: 'file',
      headers: {
        'X-HIC-info': `{"appId":${_appId},"appName":${_appName},"userId":${_userId}}`
      },
      formData: { capKey: 'xxxxxx.xxxxxx', audioFormat: 'pcm16k16bit' },
      progress: 1,
      onProgress: (_data) => {
        console.log(_data, '~~~data');
      }
    }).then(data => {
      console.log('服务端返回数据:', data);
    }).catch(error => {
      console.log('HWH5.uploadFile上传异常', error);
    });
    
  • ES5示例

    var filePath = '/downloads/xxxx.asr';
    var _appId = 'com.xxx.xxx';
    var _appName = 'xxxxxx';
    var _userId = 'xxx';
    
    HWH5.uploadFile({
      serverUrl: 'http://example.com/uploadFile', // 示例地址,非真实服务
      filePath: filePath,
      name: 'file',
      headers: {
        'X-HIC-info': 'appId:' + _appId + ',appName:' + _appName + ',userId:' + _userId
      },
      formData: { capKey: 'xxxxxx.xxxxxx', audioFormat: 'pcm16k16bit' },
      progress: 1,
      onProgress: function (_data) {
        console.log(_data, '~~~data');
      }
    }).then(function (data) {
      console.log('服务端返回数据:', data);
    }).catch(function (error) {
      console.log('HWH5.uploadFile上传异常', error);
    });
    
  • 服务端接受(Spring boot)示例:

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

HWH5.uploadFileOperation

支持版本>=10.0.5

扫码体验:

vscode-plugin

上传文件,支持取消上传

请求参数

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

注意:filePath 只能是用户选择的文件或图片,如通过chooseImage返回的图片路径

返回说明

参数 类型 说明
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: 'file',
      headers: {
        'X-HIC-info': `{"appId":${_appId},"appName":${_appName},"userId":${_userId}}`
      },
      formData: {},
      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.uploadFileOperation({
      serverUrl: '/mcloud/mag/ProxyForUpload/xxx/xxx/xxxxxx', // 示例地址,非真实服务
      filePath: filePath,
      name: 'file',
      headers: {
        'X-HIC-info': 'appId:' + _appId + ',appName:' + _appName + ',userId:' + _userId
      },
      formData: {},
      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(); // 取消上传
    })
    

HWH5.downloadFile

支持版本>=10.0.2

扫码体验:

vscode-plugin

文件下载

注意:下载文件并未进行加密处理,机密文件请使用HWH5.encryptFile进行加密

请求参数

参数 类型 必填 说明
url String 下载资源的url提示:URL中如果包含中文或者特殊字符,请使用encodeURIComponent进行处理
headers Object Object HTTP请求Header
filePath String 文件存放到本地的地址,包含文件名称及后缀(/download/test.png)

返回结果

参数 说明
status 下载成功:1

请求示例

  • ES6版本

    HWH5.downloadFile({
      url: '',
      headers: {},
      filePath: ''
    }).then(result => {
      console.log(result);
    }).catch(error => {
      console.log('下载异常', error);
    });
    
  • ES5版本

    HWH5.downloadFile({
      url: '',
      headers: {},
      filePath: ''
    }).then(function (result) {
      console.log(result);
    }).catch(function (error) {
      console.log('下载异常', error);
    });
    

HWH5.downloadFileAndEncrypt

支持版本>=10.0.2

下载文件并加密,加密后的文件只能通过HWH5.openFile打开,只支持Android

请求参数

参数 类型 必填 说明
url String 下载资源的url提示:URL中如果包含中文或者特殊字符,请使用encodeURIComponent进行处理
headers Object Object HTTP请求Header
filePath String 文件存放到本地的地址,包含文件名称及后缀(/download/test.png)

返回结果

参数 说明
status 下载成功:1

请求示例

  • ES6版本

    HWH5.downloadFileAndEncrypt({
      url: '',
      headers: {},
      filePath: ''
    }).then(result => {
      console.log(result);
    }).catch(error => {
      console.log('下载异常', error);
    });
    
  • ES5版本

    HWH5.downloadFileAndEncrypt({
      url: '',
      headers: {},
      filePath: ''
    }).then(function (result) {
      console.log(result);
    }).catch(function (error) {
      console.log('下载异常', error);
    });
    

HWH5.downloadFileOperation

支持版本>=10.0.5

扫码体验:

vscode-plugin

下载文件,支持取消下载

请求参数

参数 类型 必填 说明
url String 下载资源的url提示:URL中如果包含中文或者特殊字符,请使用encodeURIComponent进行处理
headers Object Object HTTP 请求 Header
filePath String 文件存放到本地的地址,包含文件名称及后缀(/download/test.png)
progress Number 是否返回上传进度。1:返回,0:不返回。默认为 0
onProgress Function 当progress为1时,必填。回调函数,持续回调
onSuccess Function 上传成功后回调函数
onError Function 上传失败或是异常的回调函数

返回说明

参数 类型 说明
abort Function 取消下载函数
  • ES6版本

    const downloadTask = await HWH5.downloadFileOperation({
      url: '',
      headers: {},
      filePath: '',
      progress: 1,
      onProgress: _data => console.log('进度', _data),
      onSuccess: res => console.log('--------- success', res),
      onError: err => console.log('--------- error', err)
    });
    
    downloadTask.abort(); //取消下载
    
  • ES5版本

    HWH5.downloadFileOperation({
      url: '',
      headers: {},
      filePath: '',
      progress: 1,
      onProgress: function (_data) {
        console.log('进度', _data);
      },
      onSuccess: function (res) {
        console.log('--------- success', res);
      },
      onError: function (err) {
        console.log('--------- error', err);
      }
    }).then(function (result) {
      downloadTask.abort(); //取消下载
    })
    

结果。 ""

    无结果。 ""