webdevask.com

Menu

  • Home
  • New
  • Add question

php - Laravel posting base64 file via HTTP client is not working

View Original

one text

I'm implementing third party API in Laravel where I have to send some data along with fileData with base64.

Like this:

enter image description here

To post the data I'm sending like this:

$requestUrl = $this->baseUrl . $endpoint;

$content = [
    'associatedType' => 'property',
    'associatedId' => 'XXXXXXX81',
    'typeId' => 'DET',
    'name' => '304-Smithson-Road-Details.pdf',
    "isPrivate" => false,
    'fileData' => 'data:application/pdf;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg=='
];

$response = Http::withHeaders([
    "api-version" => config("apiVersion"),
    "customer" => config("customer"),
    "Accept" => "application/json-patch+json",
    "Authorization" => "Bearer {$this->token}"
])->send($method, $requestUrl, [
    "body" => json_encode($content)
])->collect()->toArray();

return $response;

After executing the above code I'm getting null response and file is not uploaded.

Is there any mistake in HTTP request code?

Source

See also:

  • php สร้าง Google ชีตจากบัญชีบริการ

  • php - Laravel 8.0 Installation Failed

  • javascript - How to include HTML data (tags) as value in "arrayToDataTable" of Google Pie Chart?

  • how to Grouping array in php

  • php - vender folder from my laravel project has more 1k error

© 2021
E-mail: contact@webdevask.com
Back to top