abu abu
abu abu

Reputation: 7022

Upload file through API

I am updating data using API request like below.

$response = Http::withToken(Session::get('SesTok'))->post('https://sometext/profile-update', [
                "first_name" => $request->first_name,
                "last_name" => $request->last_name,
                "email" => $request->profile_email,       
            ]);

Now I need to upload File using API Request. I can fetch file details using $request->file('logo').

How can I Upload file through API ?

Upvotes: 0

Views: 251

Answers (1)

Shahrukh
Shahrukh

Reputation: 478

Use Http::attach method

    $response = Http::attach(
    'attachment', file_get_contents('photo.jpg'), 'photo.jpg'
    )->post('http://example.com/attachments');

Upvotes: 1

Related Questions