Laravel 通过API上传文件
我正在使用API请求更新数据,如下所示Laravel 通过API上传文件,laravel,api,Laravel,Api,我正在使用API请求更新数据,如下所示 $response = Http::withToken(Session::get('SesTok'))->post('https://sometext/profile-update', [ "first_name" => $request->first_name, "last_name" => $request->last_
$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上传文件?使用
Http::attach
方法
$response = Http::attach(
'attachment', file_get_contents('photo.jpg'), 'photo.jpg'
)->post('http://example.com/attachments');
谢谢@Shahrukh。我应该这样使用吗<代码>$response=Http::attach('attachment',file_get_contents($request->file('logo')),'photo.jpg')->post('http://example.com/attachments');代码>使用
文件获取内容($request->file('logo')->getRealPath())代码>