【发布时间】:2021-10-27 22:46:15
【问题描述】:
我想使用 http 客户端 laravel 更新/上传图像。我确实更新了数据,但图像没有更新。 API 是 blob 类型。我尝试在邮递员中使用表单数据文件,它确实有效。但我不知道为什么它在我的 laravel 应用程序中不起作用。
这是我的代码
$image = $request->file('profile_image');
if ($image != null) {
$contents = $image->openFile()->fread($image->getSize());
}
$response = Http::withToken($request->session()->get('user'))->acceptJson()->attach('image', file_get_contents($image))->post("https://voice.infidea.id/api/gateway/update-user", [
'id' => $user['id'],
'name' => $request->name,
'email' => $request->email,
'contact' => $request->contact
]);
我也尝试使用 $content 但仍然没有用。只有更新的字符串数据。
请有人知道为什么会这样,请帮助我真的很感激。
【问题讨论】:
-
在我的邮递员那里没问题。在代码中挖掘何时从代码中发布 API
标签: php laravel httpclient laravel-8 guzzle