发现API错误

kazike 显示全部楼层 发表于 2024-5-1 15:55:38
let config: request.agent.Config = {
  action: request.agent.Action.DOWNLOAD,
  url: 'http://127.0.0.1',
  title: 'taskStartTest',
  description: 'Sample code for start the download task',
  mode: request.agent.Mode.BACKGROUND,
  overwrite: false,
  method: "GET",
  data: "",
  saveas: "./",
  network: request.agent.Network.CELLULAR,
  metered: false,
  roaming: true,
  retry: true,
  redirect: true,
  index: 0,
  begins: 0,
  ends: -1,
  gauge: false,
  precise: false,
  token: "it is a secret"
};
request.agent.create(getContext(), config).then((task: request.agent.Task) => {
  task.start((err: BusinessError) => {
    if (err) {
      console.error(`Failed to start the download task, Code: ${err.code}, message: ${err.message}`);
      return;
    }
    console.info(`Succeeded in starting a download task.`);
  });
  console.info(`Succeeded in creating a download task. result: ${task.tid}`);
}).catch((err: BusinessError) => {
  console.error(`Failed to create a download task, Code: ${err.code}, message: ${err.message}`);
});

let attachments: Array<request.agent.FormItem> = [{ name: "taskOnTest", value: { filename: "taskOnTest.avi", mimeType: "application/octet-stream", path: "./taskOnTest.avi", } }]; let config: request.agent.Config = { action: request.agent.Action.UPLOAD, url: 'http://127.0.0.1', title: 'taskOnTest', description: 'Sample code for event listening', mode: request.agent.Mode.FOREGROUND, overwrite: false, method: "PUT", data: attachments, saveas: "./", network: request.agent.Network.CELLULAR, metered: false, roaming: true, retry: true, redirect: true, index: 0, begins: 0, ends: -1, gauge: false, precise: false, token: "it is a secret" }; let createOnCallback = (progress: request.agent.Progress) => { console.info('upload task progress.'); }; request.agent.create(getContext(), config).then((task: request.agent.Task) => { task.on('progress', createOnCallback); console.info(Succeeded in creating a upload task. result: ${task.tid}); }).catch((err: BusinessError) => { console.error(Failed to create a upload task, Code: ${err.code}, message: ${err.message}); });

您尚未登录,无法参与评论,登录后可以:
参与开源共建问题交流
认同或收藏高质量问答
获取积分成为开源共建先驱

精彩评论1

马迪

沙发 发表于 2024-5-4 12:38:13
没get到这是具体说什么错误?  包括API版本,硬件,镜像版本等是啥呢?

Copyright   ©2023  OpenHarmony开发者论坛  京ICP备2020036654号-3 |技术支持 Discuz!

返回顶部