How make post request with GuzzleHttp( version 6.0 ). I am trying do the following and getting error
i'm get the image value
Illuminate\Http\UploadedFile Object
(
[test:Symfony\Component\HttpFoundation\File\UploadedFile:private] =>
[originalName:Symfony\Component\HttpFoundation\File\UploadedFile:private] => 1.53mb.jpg
[mimeType:Symfony\Component\HttpFoundation\File\UploadedFile:private] => image/jpeg
[size:Symfony\Component\HttpFoundation\File\UploadedFile:private] => 1607671
[error:Symfony\Component\HttpFoundation\File\UploadedFile:private] => 0
[pathName:SplFileInfo:private] => C:\wamp\tmp\php32BB.tmp
[fileName:SplFileInfo:private] => php32BB.tmp
)
here i'm using guzzlehttp using to upload the image
$response = $this->client->request('POST', url('/update_profile'), [
'multipart' => [
[
'name' => 'foo',
'contents' => fopen('C:\wamp\tmp\php32BB.tmp', 'r'),//this path is image save temperary path
]
]
]);
Now i get the error fopen(C:\wamp\tmp\php17BC.tmp): failed to open stream: No such file or directory.
How to use the contents in multipart
i solved this issue
$image_path = $post_array['image']->getPathname();
$image_mime = $post_array['image']->getmimeType();
$image_org = $post_array['image']->getClientOriginalName();
$response = $this->client->post(url('/update_profile'), [
'multipart' => [
[
'name' => 'image',
'filename' => $image_org,
'Mime-Type'=> $image_mime,
'contents' => fopen( $image_path, 'r' ),
],
]
]);
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community