laravel - 通过 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 上传文件?
解决方案
使用Http::attach
方法
$response = Http::attach(
'attachment', file_get_contents('photo.jpg'), 'photo.jpg'
)->post('http://example.com/attachments');
推荐阅读
- spring - 将配置文件附加到其他弹簧配置文件
- nativescript - 构建具有最小大小的 NativeScript 空白项目
- php - 如何修复:我的字体和 @font-face 使用的所有 wordpress 图标突然被禁用
- plsql - 什么是参数化光标,我们需要在哪种情况下使用它?
- android - 发布应用程序时的应用程序启动器图标大小
- java - 如果 s(a string) 不包含 chars(another string) 中找到的任何字符,您如何编写返回 true 的代码,否则返回 false
- rust - 如何解除阻塞未来的线程并返回结果
- python - 如果条件,在python中分配错误的值
- java - 分组结果的方面计数
- c++ - win32 计时器是否归其调用线程所有?