2

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

Boopathi Saravanan
  • 133
  • 1
  • 2
  • 9
  • Do you have C:\wamp\tmp folder created? fopen would not create the directory for you if it doesn't exist. – SteD Aug 30 '16 at 06:57
  • 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' ), ], ] ]); – Boopathi Saravanan Aug 30 '16 at 07:45
  • Possible duplicate of [Failed to open stream : No such file or directory](http://stackoverflow.com/questions/36577020/failed-to-open-stream-no-such-file-or-directory) – Vic Seedoubleyew Sep 03 '16 at 11:05

1 Answers1

8

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' ),
                ],
            ]
        ]);
Boopathi Saravanan
  • 133
  • 1
  • 2
  • 9