javascript - 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);
})
解决方案
我使用encodeURI()对这个日语中的名称“PPTXサンプル.pptx”进行编码。上传文件后API自动解码日文
推荐阅读
- scala - Play Framework JSON 排序失败
- maven - Maven依赖解包 - 跳过顶级目录
- django - 在 django 应用程序中解决高 cpu 使用率问题
- python - 使用 TensorFlow Dataset api 导入可变长度的输入/输出对
- c# - 增加事件中心的吞吐量
- regex - 查找模块中的正则表达式模式(Ansible)
- python - 使用 Tensorflow 后端导入 keras 时收到警告
- python - Python计算元组列表中元素的方法
- php - 如何在php中添加firestore引用类型字段?
- html - 内联块 div 在活动状态下改变高度