How to send saved file to external API in Laravel? - Hack The Tech - Latest News related to Computer and Technology

Hack The Tech - Latest News related to Computer and Technology

Get Daily Latest News related to Computer and Technology and hack the world.

Tuesday, March 21, 2023

How to send saved file to external API in Laravel?

I'm building a NextJS webapp in which a user is supposed to complete his profile by uploading his national ID. I'm saving the uploaded file using Laravel. Everything works fine till the saving part. But when I'm trying to send the saved to file to an external API, the API throws me an error asking me to Send a valid image. The external API accepts, JPG, JPEG and PDF. Here's my code:

$pan = Storage::get(auth()->user()->pan_photo);
$data = ['pancard' => $pan,];
$response = Http::asForm()
            ->withHeaders([
                'some custom headers'
            ])->put('https://staging.eko.in:25004/ekoapi/v1/user/service/activate', $data);
Log::channel('response')->info($response);

Am I doing something wrong here?



source https://stackoverflow.com/questions/75794065/how-to-send-saved-file-to-external-api-in-laravel

No comments:

Post a Comment