php - PHP Laravel 5 使用 Guzzle 上传文件
问题描述
我正在尝试使用 Laravel 5 和 Guzzle 上传文件。我正在尝试作为表单数据发送,但我不断收到 400 错误请求。我也尝试使用 cURL 并得到了同样的错误。
这是我试图与 Guzzle 一起使用的内容。当我在 Postman 应用程序中测试它并将其作为表单数据发送时,该 API 有效。
$image = $request->image->storeAs('images', $request->image->getClientOriginalName());
$path = base_path().'/storage/app/';
$client = new Client(); //GuzzleHttp\Client
$response = $client->post($url, [
'multipart' => [
[
'name' => 'input_profile_image',
'contents' => fopen($path.'/'.$image, 'r'),
'headers' => ['Content-Type' => 'multipart/form-data']
],
[
'name' => 'input_email',
'contents' => $email,
'headers' => ['Content-Type' => 'multipart/form-data']
],
[
'name' => 'input_pass',
'contents' => $password,
'headers' => ['Content-Type' => 'multipart/form-data']
],
[
'name' => 'api_request',
'contents' => 'true',
'headers' => ['Content-Type' => 'multipart/form-data']
]
]
]);
我错过了什么?
解决方案
推荐阅读
- javascript - 是否有为 IE11 设置 babel/webpack 的简单来源?
- javascript - 通过Javascript更改元素的显示?
- osgi - OSGI 导入包问题
- r - 关于 forvalues 的等效命令
- ruby-on-rails - 在 Rails 中集成 CKEditor 自动链接插件
- c++ - 如何反转二叉搜索树?
- java - java.util.concurrent.ExecutionException:com.android.builder.internal.aapt.v2.Aapt2Exception:Android资源链接失败flutter_youtube
- elasticsearch - 重新索引和更新连接字段
- php - 在 WordPress 中使用 add_shortcode() 在主页中创建内容部分
- java - Java:搜索两个字符串之间的第一个公共字符