首页 > 解决方案 > TypeError [ERR_UNESCAPED_CHARACTERS] 路径包含日语

问题描述

我在 Nodejs 中使用 post 方法,路径包含日语。但我得到了错误:

TypeError [ERR_UNESCAPED_CHARACTERS]:请求路径包含非转义字符

路径如下:D:\SourceCode\Backend\controllers\PPTXサンプル.pptx

我尝试使用encodeURIComponent()但它没有解决问题。

const file= [
        {
            url:"D:\\SourceCode\\Backend\\controllers\\PPTXサンプル.pptx",
            name: "PPTXサンプル.pptx",
        },

    Promise.resolve()
                    .then(() => {
                        return sprLib.renewSecurityToken();
                    })
                    .then((strDigest) => {
                        return sprLib.folder(req.body.serverRelativeUrl).upload({
                            name: file.name,
                            data: fs.readFileSync(file.url),
                            requestDigest: strDigest,
                            overwrite: true,
                        });
                    })
                    .then((objFile) => {
                        console.log(
                            "SUCCESS: `" +
                            objFile.Name +
                            "` uploaded to: `" +
                            objFile.ServerRelativeUrl +
                            "`"
                        );
                    })
                    .catch((strErr) => {
                        console.log("+++++++++++++++++++++");
                        console.error(strErr);
                    })

标签: javascriptnode.js

解决方案


我使用encodeURI()对这个日语中的名称“PPTXサンプル.pptx”进行编码。上传文件后API自动解码日文


推荐阅读