Send PDF to Azure Function

veseli_oblacakveseli_oblacak Member Posts: 4
edited 2023-08-09 in NAV Three Tier
I am trying to create azure function which will take PDF sent from BC and encrypted it with password. I try two different approach.
First, to send instream from BC with content
flnuytq69y59.png

And azure function is like down there, but always got an error. Seams like I don't take stream parameter on azure function correct.
4uk6rx3jsqmw.png

I also try to convert pdf to ToBase64, and send it like dictionary parameter but got error

paxakqq37g1v.png

Answers

  • yukonyukon Member Posts: 361
    edited 2023-08-11
    Does it work when you test it on locally?
    Make Simple & Easy
  • veseli_oblacakveseli_oblacak Member Posts: 4
    yukon wrote: »
    Does it work when you test it on locally?

    I did not create it locally.
  • yukonyukon Member Posts: 361
    You got the error but you didn’t post the error message. If you post the error messages, someone can help your issue
    Make Simple & Easy
  • veseli_oblacakveseli_oblacak Member Posts: 4
    yukon wrote: »
    You got the error but you didn’t post the error message. If you post the error messages, someone can help your issue

    Internal server error :D
  • ftorneroftornero Member Posts: 524
    Hello @veseli_oblacak ,

    This is the scaffolding created for a C# Azure Function
    #r "Newtonsoft.Json"
    
    using System.Net;
    using Microsoft.AspNetCore.Mvc;
    using Microsoft.Extensions.Primitives;
    using Newtonsoft.Json;
    
    public static async Task<IActionResult> Run(HttpRequest req, ILogger log)
    {
        log.LogInformation("C# HTTP trigger function processed a request.");
    
        string name = req.Query["name"];
    
        string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
        dynamic data = JsonConvert.DeserializeObject(requestBody);
        name = name ?? data?.name;
    
        string responseMessage = string.IsNullOrEmpty(name)
            ? "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response."
                    : $"Hello, {name}. This HTTP triggered function executed successfully.";
    
                return new OkObjectResult(responseMessage);
    }
    

    And this is how the Test/Run is working.

    dtrzjiujax7w.png

    You could try it.

    Regards.
  • veseli_oblacakveseli_oblacak Member Posts: 4
    ftornero wrote: »
    Hello @veseli_oblacak ,

    This is the scaffolding created for a C# Azure Function
    #r "Newtonsoft.Json"
    
    using System.Net;
    using Microsoft.AspNetCore.Mvc;
    using Microsoft.Extensions.Primitives;
    using Newtonsoft.Json;
    
    public static async Task<IActionResult> Run(HttpRequest req, ILogger log)
    {
        log.LogInformation("C# HTTP trigger function processed a request.");
    
        string name = req.Query["name"];
    
        string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
        dynamic data = JsonConvert.DeserializeObject(requestBody);
        name = name ?? data?.name;
    
        string responseMessage = string.IsNullOrEmpty(name)
            ? "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response."
                    : $"Hello, {name}. This HTTP triggered function executed successfully.";
    
                return new OkObjectResult(responseMessage);
    }
    

    And this is how the Test/Run is working.

    dtrzjiujax7w.png

    You could try it.

    Regards.


    This was the first code I tried and its work. But I have a problem to pass and manipulate with stream.
  • ftorneroftornero Member Posts: 524
    Hello @veseli_oblacak ,

    Could you post how you pass in the body request the PDF to that Azure Functrion ?

    In my opinion is better send it in Base64.

    Regards.
Sign In or Register to comment.