小安迪
小安迪
  • 发布:2019-05-09 17:45
  • 更新:2020-06-30 11:00
  • 阅读:6024

【报Bug】uni.downloadFile下载成功后调用uni.openDocument,中文标题的文件打不开

分类:uni-app

这个是openDocument回调fail的内容:
打开文档失败:{"errMsg":"openDocument:fail:文件[_doc/uniapp_temp_1557395006892/download/%E5%85%AC%E5%8F%B82018%E5%B9%B4%E7%AC%AC%E4%BA%8C%E5%AD%A3%E5%BA%A6%E5%AE%89%E5%A7%94%E4%BC%9A+%E4%BC%9A%E8%AE%AE%E7%BA%AA%E8%A6%81.docx]读取失败:文件没有发现"}
主要是iOS的问题,安卓没问题。
亲测,英文标题的文件iOS就可以打开

2019-05-09 17:45 负责人:无 分享
已邀请:
前端打工人

前端打工人

楼主这个问题解决了吗??我也遇到这问题了

  • 小安迪 (作者)

    暂时只能把文件标题改成英文- -

    2019-05-19 20:32

心安

心安

楼主,请问安卓的中文文件打开标题会乱码吗?我的文件可以打开,内容也显示正常,就是标题乱码。

  • 小安迪 (作者)

    现在暂时没用中文标题。。

    2019-08-30 17:13

c***@163.com

c***@163.com - 新手上路,碾过坦克。

调用uni.openDocument时,如果文件名里有中文名,在filePath里的地址加上escape应该可以解决。

uni.openDocument({  
    filePath: escape(res1.tempFilePath),  
    success: function(res) {  
        console.log('打开文档成功');  
    },  
    fail: function(err) {  
        uni.showToast({  
            icon: 'none',  
            title: '打开文档失败'  
        });  
    }  
});
  • x***@163.com

    用这个方法后直接打开文档失败了。

    2020-01-21 15:05

x***@163.com

x***@163.com

请问你后面是怎么处理的。我们项目也有相同的问题

7***@qq.com

7***@qq.com

uni.downloadFile({  
                            url: `http://192.168.100.116:8765/api/file/download/${attach.id}`,  
                            header: {  
                                'Authorization': getToken()  
                            },  
                            success: (res) => {  
                                uni.hideLoading()  
                                const filePath = res.tempFilePath  
                                const originName = filePath.substring(filePath.lastIndexOf('/') + 1, filePath.length)  
                                const fileName = escape(originName)  
                                plus.io.resolveLocalFileSystemURL(filePath, orinFile => {  
                                    plus.io.resolveLocalFileSystemURL('_downloads', dstDir => {  
                                        orinFile.moveTo(dstDir, fileName, dstFile => {  
                                            uni.openDocument({  
                                                filePath: plus.io.convertAbsoluteFileSystem(dstFile.fullPath),  
                                                success: res => {  
                                                    console.log('打开文档成功', dstFile)  
                                                },  
                                                fail: (err) => {  
                                                    console.log(err)  
                                                }  
                                            })  
                                        }, err => {  
                                            console.log(err, err.message)  
                                        })  
                                    })  
                                })  
                            }  
                        });
  • 阮走高飞

    怎么设置导航栏标题为中文?

    2020-05-20 17:20

7***@qq.com

7***@qq.com

普通文件上面的处理都OK了,但是如果文件名是以%开头的,会报错, LOG如下(不修改文件名的情况下尚未解决):

errMsg: "openDocument:fail 文件[_downloads/%功能(修改).xlsx]读取失败:编码错误"

a***@qq.com

a***@qq.com - app开发小能手

uni.downloadFile({  
                    url: encodeURI(this.mwPath(1) + e),  
                    success: function(res) {  
                        console.log(res)  
                        if (res.statusCode === 200) {  
                            uni.showToast({  
                                icon:'none',  
                                position:'bottom',  
                                title :'下载成功'  
                            })  
                        }  
                        var filePath = res.tempFilePath;  
                        uni.openDocument({  
                          filePath: filePath,  
                          success: function (res) {  
                            console.log('打开文档成功');  
                          }  
                        });  
                    }  
                });

测试用encodeURI("你的中文名路径")可以下载中文文档并打开它,不晓得正式上线是否会出bug

  • 沫沫茶叶

    你们下载的文件,后缀是什么?为什么我下载的都是.html结尾的,然后都打不开

    2020-07-06 11:48

  • a***@qq.com

    回复 沫沫茶叶: word

    2020-07-10 14:39

该问题目前已经被锁定, 无法添加新回复