Bad Request reponse Guzzle para Google Storage no Laravel

Asked

Viewed 35 times

0

Good morning, I’m having a problem sending a file to Google Storage it returns me the following error:

Client error: SETURI http://dev-site.com.br/storage resulted in a 400 Bad Request sponse

My shipping code is like this:

if ($request->hasfile('path')) {

            $token = 'Codigodotoken';

            $guzzleHttpService = new GuzzleHttpClient();

            $guzzleHttpService->setUri(env('URI_API_STORAGE_SS'));
            $response = $guzzleHttpService
            ->setPath(self::PATH_STORAGE)
            ->send('post', [
                'headers' => ['Authorization' => $token],
                'multipart' => [
                    [
                        'name' => 'file',
                        'contents' => fopen($request->file->getPathName(), 'r'),
                        'path' => $request->file->getClientOriginalName()
                    ],
                    [
                        'name' => 'permission_id',
                        'contents' => 1
                    ],
                    [
                        'name' => 'status_id',
                        'contents' => 2
                    ],
                    [
                        'name' => 'type_file_id',
                        'contents' => 6
                    ],
                    [
                        'name' => 'user_id',
                        'contents' => $file->getUserId()
                    ],
                ]
            ]);

            dd($response);

I’m not able to identify if the problem is in the request or the way I’m trying to send the file.

  • The "Contents" of the "file" actually receives a stream file or should receive the contents of the file?

  • She actually gets a stream, at least the model they passed me that they were using is this way even, what was not passed me was how I capture this

  • I would recommend making this request in Postman or alternative software to know exactly what the request is you need to make, then migrate it to Guzzle.

  • I was able to check on Postman and it really is the same file,$request->file, but still persists bad request error, at least I know that the problem is not in my file, sending the post by Postman it sends and returns me correctly, but by my application returns the error

  • Da a relida na doc, as I remember is missing information, da uma relida na doc.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.