You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Native Android端下载管理器返回状态码16失败求助

Android端react-native-blob-util下载Zip文件报错Status Code=16的排查思路

问题场景:使用react-native-blob-util实现从服务端下载Zip文件,iOS全环境正常,仅Android生产环境报错:

ExceptionsManager.js:149 Error downloading file Error: Download manager failed to download from  <download_url> Status Code = 16

已排除认证问题,相关代码如下:

const FILE_URL = uri;

const { config, fs } = ReactNativeBlobUtil;
const { dirs } = fs;
let writePath = dirs.DocumentDir;
if (Platform.OS === 'android') {
  writePath = `${dirs.DownloadDir.split('Android')[0]}Download`;
}

const options = {
  fileCache: true,
  addAndroidDownloads: {
    path: writePath + '/' + fileName + '.' + fileExtension,
    description: `Downloading ${fileName}{}`,
    notification: true,
    useDownloadManager: true,
  },
};

return await config(options)
  .fetch('GET', FILE_URL, {
    'Authorization': `Bearer ${authToken}`,
    'Content-Type': 'application/zip',
  })
  .then(() => {
    // Handle download success
  })
  .catch((e) => {
    // Handle download failure
  });

以下是针对性的排查解决思路:

  • 修正Android存储路径的处理逻辑
    生产环境Android的文件系统权限限制更严格,手动通过split('Android')截取路径的方式不可靠,不同设备的DownloadDir结构可能存在差异:

    • 直接使用dirs.DownloadDir作为基础路径拼接文件名,比如${dirs.DownloadDir}/${fileName}.${fileExtension}
    • 提前确认目标目录是否存在,生产环境中需手动创建目录:
      await fs.mkdir(writePath, { recursive: true });
      
    • 确保addAndroidDownloads中的path是合法绝对路径,适配Android 10+的Scoped Storage规则,避免因存储权限导致的访问失败
  • 解决配置项冲突问题
    当开启useDownloadManager: true时,fileCache: true会产生逻辑冲突——Download Manager会自行处理文件存储,无需再启用文件缓存,建议将fileCache设为false或直接移除该配置

  • 调整请求头的合理性
    GET请求携带Content-Type头不符合HTTP规范,生产环境服务端可能对请求头校验更严格,尝试移除Content-Type请求头

  • 排查系统级权限与限制

    • 检查生产环境设备的Download Manager是否被禁用,或存在系统级网络限制(如后台网络权限)
    • Android 12+需要申请POST_NOTIFICATIONS权限才能显示下载通知,需在AndroidManifest.xml中添加权限声明,并在运行时主动请求该权限
  • 添加详细日志定位问题
    在catch块中打印完整错误信息:

    .catch((e) => {
      console.log('下载错误详情:', e.message, e.stack, e.status);
      // 处理下载失败逻辑
    });
    

    同时通过adb命令查看Android原生Download Manager日志:adb logcat -s DownloadManager,获取更底层的错误原因

内容的提问来源于stack exchange,提问作者Rameez Hussain

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.25 07:15:38