我正在尝试通过UploadedFile
将Laravel GuzzleHTTP
实例发送到另一个应用程序。 post
可以通过,但是多部分表单不能正确传递:
$image_path = $data['post_field']->getPathname();
$image_mime = $data['post_field']->getmimeType();
$image_org = $data['post_field']->getClientOriginalName();
$response = $this->client->post($uri, [
'headers' => [
'Content-Type' => 'application/json',
'Authorization' => 'Bearer ' . $bearerToken,
],
'multipart' => [
[
'name' => 'post_field',
'filename' => $image_org,
'Mime-Type'=> $image_mime,
'contents' => fopen( $image_path, 'rb' ),
],
]
]);
我还尝试创建一个GuzzleHttp\Psr7\Request
实例。不幸的是,json_encode
对UploadedImage
的使用无济于事,因为编码对象将转换为NULL
。我应该将正文转换为Stream
吗?如果是这样,那将如何工作?
$request = new Request($method, $uri, $headers, $body);
有什么我想念的吗?