首页 > 解决方案 > 通过 API 上传文件

问题描述

我正在使用如下 API 请求更新数据。

$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,       
            ]);

现在我需要 使用 API 请求上传文件。我可以使用$request->file('logo').

如何通过 API 上传文件?

标签: laravelapi

解决方案


使用Http::attach方法

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

推荐阅读