[Bug]: capacitor/http Upload progress not supported

未关闭
#8,241 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
48/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
领域
api, mobile-dev

调研方向

首先检查 Capacitor HTTP plugin 对原生 iOS URLSession 的使用以及 Android 对 RequestBody 的处理,然后将其与 Capacitor File Transfer plugin 的进度实现进行比较。当两个平台都发出包含可用进度数据的 uploadProgress 通知,并且现有的下载行为保持不变时,工作即完成。

由索引模型根据 Issue 内容生成。

描述

Capacitor Version

I would like to address an issue that was automatically closed. I am having the same problem.

https://github.com/ionic-team/capacitor/issues/6658

Currently, the Capacitor HTTP plugin does not emit upload progress events, so passing onUploadProgress in requests has no effect. This is not a bug in user code — it is a limitation of the plugin:
• iOS: Uses URLSession.shared without a delegate. Upload progress requires implementing urlSession(_:task:didSendBodyData:totalBytesSent:totalBytesExpectedToSend:).
• Android: Uses RequestBody directly without a wrapper. Upload progress requires a custom RequestBody that reports bytes written.

By contrast, the Capacitor File Transfer plugin handles native upload progress correctly on both platforms.

Upload progress is critical for mobile apps that handle large files. Adding native support would allow the Capacitor HTTP plugin to:
1. Support progress bars and UI feedback during uploads.
2. Reach feature parity with web APIs like XHR and Axios.
3. Make Capacitor a complete solution for file uploads without relying on additional plugins.

Request: Please add native upload progress support on iOS and Android, and expose it via notifyListeners("uploadProgress") so developers can track upload progress natively.

Platforms Affected
  • iOS
  • Android
  • Web
Current Behavior

I hooked up the onprogress event in my code to show the progress of downloading a file to the user. But enabling the @capacitor/http plugin the progress doesn't show up anymore. I only see the popup and when the downloading is done, it will show the file. When I disable the plugin, the progress is shown again.

Expected Behavior

The user should see the progress of the download.

Project Reproduction
makeXMLRequest(method, params, headers, useDatabase=true, cancelFunc, progressFunc)  {
  const req = this.checkParams(params, headers, useDatabase);
  if (req.error !== undefined && req.error !== null) {
    return Promise.reject(req.error);
  }

  return new Promise((resolve, reject) => {
    let fetch = new XMLHttpRequest();

    if (cancelFunc !== undefined && cancelFunc !== null) {
      cancelFunc.cancel = () => {
        fetch.abort(null);
      };
    }
    // open a connection
    fetch.open("POST", req.host);
    // set extra request headers
    for (const key in req.headers) {
      fetch.setRequestHeader(key, req.headers[key]);
    }

    fetch.onload = (oEvent) => {
      if (fetch.status >= 200 && fetch.status < 300) {
        // difference between @capacitor/http and the 'normal' XMLHttpRequest
        // @capacitor/http returns already a JSON
        const result = JSON.parse(fetch.response);
        resolve(result.result);
      } else {
        reject(fetch.statusText);
      }
    };
    // send progress data back
    fetch.onprogress = (oEvent) => {
      if (progressFunc !== undefined && progressFunc !== null) {
        progressFunc(oEvent.loaded, oEvent.total);
      }
    };

    fetch.onerror = (oEvent) => {
      reject(fetch.statusText);
    };
    // abort the connection
    fetch.onabort = (oEvent) => {
      reject(false);
    };
    // send the data
    fetch.send(JSON.stringify(
      {method: method, params: req.params, id: req.uid}
    ));
  });
}
主要语言
TypeScript
星标
17.1k
派生
1.3k
平均合并
1 天 22 小时
30 天内合并 PR
26

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

ionic-team/capacitor 的其他 Issue

查看 ionic-team/capacitor 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。