【发布时间】:2020-02-06 21:49:12
【问题描述】:
上下文
我正在为一个会计机器人做概念证明。部分解决方案是处理收据。用户制作收据图片,机器人提出一些问题并将其存储在会计解决方案中。
接近
我正在使用 BotFramework nodejs 示例 15.handling 附件,它将附件加载到数组缓冲区中并将其存储在本地文件系统中。准备好被提取并发送到会计软件的api。
async function handleReceipts(attachments) {
const attachment = attachments[0];
const url = attachment.contentUrl;
const localFileName = path.join(__dirname, attachment.name);
try {
const response = await axios.get(url, { responseType: 'arraybuffer' });
if (response.headers['content-type'] === 'application/json') {
response.data = JSON.parse(response.data, (key, value) => {
return value && value.type === 'Buffer' ? Buffer.from(value.data) : value;
});
}
fs.writeFile(localFileName, response.data, (fsError) => {
if (fsError) {
throw fsError;
}
});
} catch (error) {
console.error(error);
return undefined;
}
return (`success`);
}
在本地运行它就像一个魅力(也感谢 mdrichardson - MSFT)。存储在 Azure 上,我得到了
向您的机器人发送此消息时出错:HTTP 状态代码 InternalServerError
我将问题缩小到代码的第二部分。写入本地文件系统(fs.writefile)的部分。小文件和大文件导致 Azure.fs.writefile 接缝无法找到文件的相同错误
根据流日志发生了什么:
用户上传的附件保存在 Azure 上
{ contentType: '图片/png',contentUrl: 'https://webchat.botframework.com/attachments//0000004/0/25753007.png?t=',name: 'fromClient::25753007.png' }
localFilename(附件的目的地)解析为
localFileName: D:\home\site\wwwroot\dialogs\fromClient::25753007.png
Axios 将附件加载到数组缓冲区中。其回应:
response.headers.content-type: image/png
这很有趣,因为在本地它是 'application/octet-stream'
fs 抛出错误:
fsError: Error: ENOENT: no such file or directory, open 'D:\home\site\wwwroot\dialogs\fromClient::25753007.png
非常感谢一些帮助。
【问题讨论】:
-
从日志中可以看到文件路径有特殊字符。见
fromClient::25753007这可能是个问题 -
Tnx。会调查的。猜猜是axios处理bufferarray的结果
-
嗨,怎么样?问题解决了吗?
-
不。还是一样的错误。今天我将尝试弄清楚添加 ::fromClient 前缀的原因以及原因。
-
从 Attachment.name 中删除 ::fromClient 前缀为我解决了这个问题。不知道它的目的是什么,但对于我的 POC 来说现在可以了。
标签: node.js azure axios botframework fs