问题
I want to upload an image to a webservice using Lumen + Guzzle 6. The external web service does not accept "base64-encoding" the image to be sent. Only the image file is accepted as such.
But I still get an error message from the external webservice/API that the image could not be found or it rather seems to be that Guzzle sent the request without the image. The check with file_exists($filename_with_path) responded successfully, therefore access to the file is generally possible.
If I work with cURL-command-line on the console, it worked fine for me:
curl -v --user "username:password" ...
Thank you very much for every hint.
Here is a bit of the problem-code:
$filename_with_path = storage_path( 'app/pics/') . $file_name;
$fileContent = File::get( $filename_with_path );
$mime_type = File::mimeType( $filename_with_path );
$this->guzzle_client = null;
$this->guzzle_client = new Client( [
'auth' => [
'username',
'password'
],
'multipart' => [
[
'name' => $file_name,
'filename' => $file_name,
'contents' => $fileContent,
'mime-type' => $mime_type,
'headers' => [ 'Content-Type' => $mime_type ]
],
],
] );
// send
$this->response = $this->guzzle_client->request( 'PUT', $base_url . $endpoint );
来源:https://stackoverflow.com/questions/60882734/upload-image-to-external-webservice-api-using-lumen-laravel-and-guzzle-6