在 Business Central 中通过 HTTP Post 发送 Word 文档(无需 OnPrem 范围)

发布于 2025-01-10 03:51:42 字数 158 浏览 0 评论 0原文

我需要能够在 Business Central 中通过 HTTP POST 发送 Word 文档。它需要发送到接收两个 Word 文档的 Azure 函数。 我如何将 Word 文档上传到 Business Central(我假设通过 UploadIntoStream),然后通过 HTTP 发送文件?

I need to be able to send a Word document over HTTP POST in Business Central. It needs to be sent to an Azure Function that takes in two Word documents.
How would I go about uploading the Word documents to Business Central (I Assume through UploadIntoStream) and then sending the files over HTTP?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

桃酥萝莉 2025-01-17 03:51:42

你是对的,你需要将文件上传到流中并通过 HTTP 发送。根据您的 Azure 函数,您需要对其进行 Base64 编码或将其作为二进制文件发送。这应该对您有所帮助。

下面的模型代码告诉您如何将上传的文件插入到 HTTP 请求中,但它不包含完全工作的、经过身份验证的 HTTP 请求。这取决于您的 Azure Function 设置。

    procedure SendUploadedFileToAPI() result: JsonObject
    var
        Base64Convert: Codeunit "Base64 Convert";
        Instr: InStream;
        jObject: JsonObject;
        Client: HttpClient;
        Response: HttpResponseMessage;
        Content: HttpContent;
        ContentHeaders: HttpHeaders;
        UploadFilename: Text;
        SelectFileLbl: Label 'Select a file';
        CannotConnectErr: Label 'Cannot connect';
    begin
        UploadIntoStream(SelectFileLbl, '', 'All files (*.*)|*.*', UploadFilename, InStr);

        // Use a json with base64
        jObject.Add('file', Base64Convert.ToBase64(Instr));
        Content.WriteFrom(Format(jObject));
        Content.GetHeaders(ContentHeaders);
        ContentHeaders.Clear();
        ContentHeaders.Add('Content-Type', 'application/json');

        // Or send as binary
        Content.WriteFrom(Instr);
        ContentHeaders.Add('Content-Type', 'application/json');

        if not Client.Post('url', Content, Response) then
            Error(CannotConnectErr);
    end;

You are correct, you need to upload the file into a stream and send it over HTTP. Depending on your azure function you need to either base64 encode it or send it as a binary. This should help you on your way.

The below is mockup code that tells you how to insert an uploaded file into a HTTP request but it does not contain a fully working, authenticated HTTP request. That depends on you Azure Function setup.

    procedure SendUploadedFileToAPI() result: JsonObject
    var
        Base64Convert: Codeunit "Base64 Convert";
        Instr: InStream;
        jObject: JsonObject;
        Client: HttpClient;
        Response: HttpResponseMessage;
        Content: HttpContent;
        ContentHeaders: HttpHeaders;
        UploadFilename: Text;
        SelectFileLbl: Label 'Select a file';
        CannotConnectErr: Label 'Cannot connect';
    begin
        UploadIntoStream(SelectFileLbl, '', 'All files (*.*)|*.*', UploadFilename, InStr);

        // Use a json with base64
        jObject.Add('file', Base64Convert.ToBase64(Instr));
        Content.WriteFrom(Format(jObject));
        Content.GetHeaders(ContentHeaders);
        ContentHeaders.Clear();
        ContentHeaders.Add('Content-Type', 'application/json');

        // Or send as binary
        Content.WriteFrom(Instr);
        ContentHeaders.Add('Content-Type', 'application/json');

        if not Client.Post('url', Content, Response) then
            Error(CannotConnectErr);
    end;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文