目录

应用内下载的非图片、视频类文件,在设备上找不到

问题现象

用户在应用中选择下载非图片、视频类的文件后,在应用内可以看到文件已下载到"已下载"的目录下,但是进行查看,却找不到该路径和已经下载的文件。

但是对于图片、视频等媒体类型的文件,在应用内下载后,可以在用户的相册中看到对应的文件。

背景知识

问题定位

  1. 根据HiLog日志进行定位,根据关键字"storage"进行检索:
    07-15 13:56:49.070   51395-51395   C01406/com.hm.example/OHOS::RS  com.hm.example  I     RSUIDirector::PostTask messageId:78, cmdCount:2, instanceId:100000
    07-15 13:56:49.172   51395-52404   C015B0/com.hm.example/NETSTACK  com.hm.example  I     [http_exec.cpp:418] taskid=-2147483647, size:1179024, dns:0.079, connect:0.486, tls:0.000, firstSend:0.201, firstRecv:131.338, total:503.940, redirect:0.000, errCode:0, RespCode:200, httpVer:2, method:GET, osErr:0
    07-15 13:56:49.174   51395-51395   C03F01/com.hm.example/NAPI  com.hm.example  I     [(:467)(HandleTaskResultCallback)] taskpool:: Task PerformTask End: taskId : 394970511104, performResult : Successful
    07-15 13:56:49.175   51395-51395   A03D00/com.hm.example/JSAPP  com.hm.example  I     沙箱路径 根路径已存在: /data/storage/el2/base/haps/entry/files
    07-15 13:56:49.175   51395-51395   A03D00/com.hm.example/JSAPP  com.hm.example  I     file exists
    07-15 13:56:49.175   51395-51395   A03D00/com.hm.example/JSAPP  com.hm.example  I     file exists
    07-15 13:56:49.175   51395-51395   A03D00/com.hm.example/JSAPP  com.hm.example  I     file exists
    07-15 13:56:49.175   51395-51395   A03D00/com.hm.example/JSAPP  com.hm.example  I     file exists
    07-15 13:56:49.176   51395-51395   A03D00/com.hm.example/JSAPP  com.hm.example  I     file exists
  1. 以上日志信息中有存储的文件路径信息:/data/storage/el2/base/haps/entry/files,该文件路径为文件沙箱目录。

    目录名

    Context属性名称

    类型

    说明

    base

    NA

    本设备文件路径

    应用在本设备上存放持久化数据的目录,子目录包含files/、cache/、temp/和haps/;随应用卸载而清理。

分析结论

由于应用将非媒体文件直接存储在应用沙箱目录,而用户无法直接访问应用沙箱目录,所以导致了下载的非媒体文件对用户不可见。

修改建议

常见FAQ

Q:应用内下载文件后,如何跳转到文件所在目录以便转发到其他应用?

A:通过保存文档类文件的方式获取文件保存的uri,打印该uri即可获取文件路径。uri本身不具备跳转能力,需要通过拉起系统应用(如文件管理器或分享面板)并传递该uri来实现跳转或转发。可以使用openLink的方式打开,在openLink接口的link字段中传入系统文件管理页面的URL信息,具体请参考如何跳转到系统文件管理App界面。