将文件从缓冲区写入文件系统时,Azure内部服务器错误 [英] Internal server error om Azure when writing file from buffer to filesystem

查看:119
本文介绍了将文件从缓冲区写入文件系统时,Azure内部服务器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

上下文

我正在为会计机器人开发概念证明.解决方案的一部分是处理收据.用户对收据进行图片处理,机器人会询问一些问题并将其存储在会计解决方案中.

I am working on a Proof of Concept for an accounting bot. Part of the solution is the processing of receipts. User makes picture of receipt, bot asks some questions about it and stores it in the accounting solution.

方法

我正在使用BotFramework nodejs示例15.处理附件,该附件将附件加载到arraybuffer中并将其存储在本地文件系统中.准备好拿起并发送到会计软件的api.

I am using the BotFramework nodejs example 15.handling attachments that loads the attachment into an arraybuffer and stores it on the local filesystem. Ready to be picked up and send to the accounting software's 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上,我得到

Running locally it all works like a charm (also thanks to mdrichardson - MSFT). Stored on Azure, I get

发送此消息到您的机器人时出错:HTTP状态代码InternalServerError

There was an error sending this message to your bot: HTTP status code InternalServerError

我将问题缩小到代码的第二部分.写入本地文件系统(fs.writefile)的部分.小文件和大文件在Azure.fs.writefile接缝无法找到文件时导致相同的错误

I narrowed the problem down to the second part of the code. The part that write to the local filesystem (fs.writefile). Small files and big files result in the same error on Azure.fs.writefile seams unable to find the file

根据流日志,发生了什么事

What is happpening according to stream logs:

用户上传的附件保存在Azure上

Attachment uploaded by user is saved on Azure

{contentType:"image/png",contentUrl: ' https://webchat.botframework.com/attachments//0000004/0/25753007.png ?t =<一个非常长的字符串>',name:'fromClient :: 25753007.png'}

{ contentType: 'image/png',contentUrl: 'https://webchat.botframework.com/attachments//0000004/0/25753007.png?t=< a very long string>',name: 'fromClient::25753007.png' }

localFilename(附件的目标)解析为

localFilename (the destination of the attachment) resolves into

localFileName:D:\ home \ site \ wwwroot \ dialogs \ fromClient :: 25753007.png

localFileName: D:\home\site\wwwroot\dialogs\fromClient::25753007.png

Axios将附件加载到数组缓冲区中.回应:

Axios loads the attachment into an arraybuffer. Its response:

response.headers.content-type:image/png

response.headers.content-type: image/png

这很有趣,因为它在本地是'application/octet-stream'

This is interesting because locally it is 'application/octet-stream'

fs引发错误:

fsError:错误:ENOENT:没有这样的文件或目录,打开'D:\ home \ site \ wwwroot \ dialogs \ fromClient :: 25753007.png

fsError: Error: ENOENT: no such file or directory, open 'D:\home\site\wwwroot\dialogs\fromClient::25753007.png

真的很感谢一些帮助.

推荐答案

从attachment.name中删除:: fromClient前缀即可解决此问题.正如@Sandeep在评论中提到的那样,特殊字符可能在哪里出现问题.不知道它的目的是什么.将在Botframework示例库github存储库中提及. [更新]团队将解决此问题.是由直线服务引起的.

Removing ::fromClient prefix from attachment.name solved it. As @Sandeep mentioned in the comments, the special characters where probably the issue. Not sure what its purpose is. Will mention it in the Botframework sample library github repository. [update] team will fix this. Was caused by directline service.

这篇关于将文件从缓冲区写入文件系统时,Azure内部服务器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆