I get this error when sending a file to an api, It sent the file by POST through the guzzle library, this is the code where I send the file
$client = new Client([
'base_uri' => 'http://192.168.2.10:8000/api/archivos',
'timeout' => 10.0,
]);
$response = $client->request('POST', 'http://192.168.2.10:8000/api/archivos', [
'multipart' => [
[
'name' => '123.pdf',
'contents' => fopen('archivos/123.pdf', 'r')
],
]
]);
I am sending the fixed file but the intention is to send it through a request with INSOMNIA. This is the error:
Once the file can be sent, it must have received it in the other api, but I don't know how to respond to the request I make, that is, send the file and then save it in the other api and finally return it. Thank you
The
base_uri
is the common thing that your routes have, usually it is the domain. For example , if you want to access these routes:As you can see, the base is what is underlined since it is something common between those two routes. So you would create the client like this:
Later, since you already have the base, you only have to add the relative path, which will be where you want to go:
In your case, your base_uri is a full path and then when making the request, you put the same path back.
Given the explanation above, your Guzzle should look like this: