SthisiskelvinK
1 month ago
104
2
Laravel

Laravel PDF is creating problem

Posted 1 month ago by SthisiskelvinK

so for an application i have to send a pdf into an api then do some stuff with the pdf and then send it to another api and then return the result

problem n1:

i dont know how to get access to the pdf i sent with Postman i tried

$file = $request->get('upload_file'); 

which doesnt seem to work since i cant get the file which is called

test.pdf and has a content of

Test Dit is een test so in the meantime i do

$parser = new Parser();
$pdf = $parser->parseFile('pdf/test.pdf');
$text = pdf->getText();

problem n2:

the api i sent the transformed pdf to claims the requestbody is invalid i use Guzzle for the request

    $headers =
        [
            'headers' => [
                'Ocp-Apim-Subscription-Key' => 'xxxxxxxxxxxxxxxxxxxxxxx',
                'Accept' => 'application/json',
                'Content-Type' => 'application/json']
        ];
    $body =
        '{
            "documents": [
            {
            "language": "nl",
            "id": "1",
            "text":"' . $text . '"}
            ]
        }';

    $client = new Client();

    $response = $client->request('POST', 'https://westeurope.api.cognitive.microsoft.com/text/analytics/v2.0/KeyPhrases', $headers, $body);

it gives

`Client error: `POST
https://westeurope.api.cognitive.microsoft.com/text/analytics/v2.0/KeyPhrases
     resulted in a400 Bad Requestresponse:\n
     {"code":"BadRequest","message":"Invalid request","innerError": 
     {"code":"InvalidRequestBodyFormat","message":"Request body 
     (truncated...)\n //cant seem to format this correctly

so can anyone plz help me? and explain what i am doing wrong if they have the time

Please sign in or create an account to participate in this conversation.